Play simple beep with python without external library

a sandwhich picture a sandwhich · Dec 17, 2010 · Viewed 43.9k times · Source

Using only the modules that come with a standard python 2.6 installation, would it be possible to play a simple beeping noise?

Answer

David Wolever picture David Wolever · Dec 17, 2010

If you're on a Unix terminal, you can print "\a" to get a terminal bell:

>>> def beep():
...     print "\a"
>>> beep()

Of course, that will print a newline too… So sys.stdout.write("\a") might be better. But you get the idea.