1

I started reading about python yesterday. I am reading a book about python for absolute beginners. It is somewhat old, but I got to the part about printing "\a". The book says you could make the program sound the bell multiple times, but my computer only rings it once. I am using Python 2.7.12, and the book uses an earlier version. Is that why? Or does it only work in Python 3? I have Windows 10 on Lenovo laptop. Right now I have: print "\a\a"; print '\a' raw_input("\n\nPress enter to exit")

5
  • On my machine (OSX with Python 2.7.11), print "\a\a"; print '\a' causes the bell to ring three times, as expected. Commented Nov 20, 2016 at 13:30
  • Just tried that. Didn't work unfortunately. Guess I better be more specific. I am running on Windows 10, with a Lenovo Y50-70 laptop. If that helps at all. Commented Nov 20, 2016 at 13:35
  • when you open console, and write following command echo [Alt-7][Alt-7][Alt-7] how many beeps do you hear? Alt- left alt key, 7- numeric keyboard 7 Commented Nov 20, 2016 at 13:44
  • 0 :/ I tried that with ^G too Commented Nov 20, 2016 at 13:52
  • @lukbl Ok oops, with ^G three times it only rings once Commented Nov 20, 2016 at 14:03

2 Answers 2

2

as stated in this answer : Here

The reason it doesn't beep is that \a (or ^G) is the terminal bell code; it's up to the program handling stdout to turn that into a sound. Terminal.app will play a sound (unless you configure it to do "visual bell" instead, of turn it off entirely)

You can also try

as stated Here

import sys sys.stdout.write('\a') sys.stdout.flush() 

Hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Your answer helps me understand why this isn't working. However, I didn't originally specify that I have Windows. Is there something different for that? Or something I need to install? The sys code only rang one bell again. Thanks for the help.
I think the problem is with the command window itself in windows ( i'm not a very expert in CMD since I'm a Linux user ) maybe there is some configuration for it to sound the bell more than once ? try researching that.
0

There is an alternate way on making a beep sound multiple times:

import winsound Freq = 2500 # Set Frequency To 2500 Hertz Dur = 1000 # Set Duration To 1000 ms == 1 second winsound.Beep(Freq,Dur) winsound.Beep(Freq,Dur) 

2 Comments

I'm guessing something is wrong with my python program because I can't even import winsound. The variables don't change colors either.
Maybe you don't have it installed.Type and run this on a terminal/cmd: pip install winsound.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.