# Clear screen and beep for Python 3.x+ in Linux...# Original idea copyright, (C)2010, B.Walker, G0LCU.# Issued as PD for LXF, October 2010.# You may do with this code as you please...## Tested on Python 3.1.2 inside PCLinuxOS 2009.## Filename is "clr3x.py" and placed in the Python "Lib" drawer.## ====================# Usage:-# -------# >>> import clr3x[RETURN/ENTER]# ====================# Called as:-# -----------# clr3x.clrscn()# To clear a terminal/console window.## clr3x.beep()# To generate an error beep 0.5 seconds long, (sinewave).## clr3x.both()# To generate a beep and then clear a terminal/console window.# ====================

# Import "os" only as "sys" is not needed for this version.# import sysimport os

# This is the beep function.def beep(): # Set up the binary code as a crude sinewave. waveform=b'\x0f\x2d\x3f\x2d\x0f\x03\x00\x03' # Set audio timing to zero, "0". count=0 # Open up the audio device to write to. audio=open('/dev/audio', 'wb') # A "count" value of 1 = 1mS, so 500 = 0.5S. while count<500: # Send 8 bytes of data to the audio device 500 times. # This is VERY close to 1KHz. audio.write(waveform) count=count+1 # Close the audio device access. audio.close()