0

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")

Logan
  • 1
  • 1
  • 4
  • On my machine (OSX with Python 2.7.11), `print "\a\a"; print '\a'` causes the bell to ring three times, as expected. – Curt F. Nov 20 '16 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. – Logan Nov 20 '16 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 – lukbl Nov 20 '16 at 13:44
  • 0 :/ I tried that with ^G too – Logan Nov 20 '16 at 13:52
  • @lukbl Ok oops, with ^G three times it only rings once – Logan Nov 20 '16 at 14:03

2 Answers2

1

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.

Community
  • 1
  • 1
Michael Yousrie
  • 1,132
  • 2
  • 10
  • 20
  • 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. – Logan Nov 20 '16 at 13:44
  • 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. – Michael Yousrie Nov 20 '16 at 13:49
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)
Taufiq Rahman
  • 5,600
  • 2
  • 36
  • 44
  • I'm guessing something is wrong with my python program because I can't even import winsound. The variables don't change colors either. – Logan Nov 20 '16 at 13:56
  • Maybe you don't have it installed.Type and run this on a terminal/cmd: pip install winsound. – Taufiq Rahman Nov 20 '16 at 14:02