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")
2 Answers
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.
2 Comments
Logan
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.
Michael Yousrie
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.
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
Logan
I'm guessing something is wrong with my python program because I can't even import winsound. The variables don't change colors either.
Taufiq Rahman
Maybe you don't have it installed.Type and run this on a terminal/cmd: pip install winsound.
print "\a\a"; print '\a'causes the bell to ring three times, as expected.echo [Alt-7][Alt-7][Alt-7]how many beeps do you hear? Alt- left alt key, 7- numeric keyboard 7