<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
  <title>Linux Format forums</title>
  <link>http://linuxformat.com/forums/index.php</link>
  <description>Help, discussion, magazine feedback and more</description>
  <language>english</language>
  <copyright>(c) Copyright Sun May 26, 2013 8:13 am by Linux Format forums</copyright>
  <managingEditor>webmaster@linuxformat.com</managingEditor>
  <webMaster>webmaster@linuxformat.com</webMaster>
  <pubDate>Sun May 26, 2013 8:13 am</pubDate>
  <lastBuildDate>Sun May 26, 2013 8:13 am</lastBuildDate>
  <docs>http://backend.userland.com/rss</docs>
  <generator>phpBB2 RSS Syndication Mod by Lucas</generator>
  <ttl>1</ttl>

  <image>
    <title>Linux Format forums</title>
    <url></url>
    <link>http://linuxformat.com/forums/</link>
    <description>Help, discussion, magazine feedback and more</description>
  </image>

                                      <item>
                                        <title>Clear screen and beep for Python 3.x using STANDARD Python.</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=93731#93731</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=58561'&gt;Bazza&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Mon Oct 11, 2010 9:08 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Hi all...&lt;br /&gt;
&lt;br /&gt;
&amp;quot;clr3x.py&amp;quot; a Python 3.x Linux only derivative of my &amp;quot;clr.py&amp;quot;&lt;br /&gt;
for versions 1.4x to 2.7x for multi-platforms.&lt;br /&gt;
&lt;br /&gt;
Another STANDARD Python freebie to clear a terminal/console&lt;br /&gt;
window running Python and/or give an error beep also.&lt;br /&gt;
&lt;br /&gt;
Tested on Python 3.1.2 for PCLinuxOS 2009 and issued as PD&lt;br /&gt;
for LXF.&lt;br /&gt;
&lt;br /&gt;
If it is of any use to you Python coders you may do with it&lt;br /&gt;
as you please.&lt;br /&gt;
&lt;br /&gt;
Watch for wordwrapping etc...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;&lt;br /&gt;
# Clear screen and beep for Python 3.x+ in Linux...&lt;br /&gt;
# Original idea copyright, &amp;#40;C&amp;#41;2010, B.Walker, G0LCU.&lt;br /&gt;
# Issued as PD for LXF, October 2010.&lt;br /&gt;
# You may do with this code as you please...&lt;br /&gt;
#&lt;br /&gt;
# Tested on Python 3.1.2 inside PCLinuxOS 2009.&lt;br /&gt;
#&lt;br /&gt;
# Filename is &amp;quot;clr3x.py&amp;quot; and placed in the Python &amp;quot;Lib&amp;quot; drawer.&lt;br /&gt;
#&lt;br /&gt;
# ====================&lt;br /&gt;
# Usage&amp;#58;-&lt;br /&gt;
# -------&lt;br /&gt;
# &amp;gt;&amp;gt;&amp;gt; import clr3x&amp;#91;RETURN/ENTER&amp;#93;&lt;br /&gt;
# ====================&lt;br /&gt;
# Called as&amp;#58;-&lt;br /&gt;
# -----------&lt;br /&gt;
# clr3x.clrscn&amp;#40;&amp;#41;&lt;br /&gt;
# To clear a terminal/console window.&lt;br /&gt;
#&lt;br /&gt;
# clr3x.beep&amp;#40;&amp;#41;&lt;br /&gt;
# To generate an error beep 0.5 seconds long, &amp;#40;sinewave&amp;#41;.&lt;br /&gt;
#&lt;br /&gt;
# clr3x.both&amp;#40;&amp;#41;&lt;br /&gt;
# To generate a beep and then clear a terminal/console window.&lt;br /&gt;
# ====================&lt;br /&gt;
&lt;br /&gt;
# Import &amp;quot;os&amp;quot; only as &amp;quot;sys&amp;quot; is not needed for this version.&lt;br /&gt;
# import sys&lt;br /&gt;
import os&lt;br /&gt;
&lt;br /&gt;
# This is the beep function.&lt;br /&gt;
def beep&amp;#40;&amp;#41;&amp;#58;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; # Set up the binary code as a crude sinewave.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; waveform=b'\x0f\x2d\x3f\x2d\x0f\x03\x00\x03'&lt;br /&gt;
&amp;nbsp; &amp;nbsp; # Set audio timing to zero, &amp;quot;0&amp;quot;.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; count=0&lt;br /&gt;
&amp;nbsp; &amp;nbsp; # Open up the audio device to write to.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; audio=open&amp;#40;'/dev/audio', 'wb'&amp;#41;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; # A &amp;quot;count&amp;quot; value of 1 = 1mS, so 500 = 0.5S.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; while count&amp;lt;500&amp;#58;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Send 8 bytes of data to the audio device 500 times.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # This is VERY close to 1KHz.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; audio.write&amp;#40;waveform&amp;#41;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; count=count+1&lt;br /&gt;
&amp;nbsp; &amp;nbsp; # Close the audio device access.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; audio.close&amp;#40;&amp;#41;&lt;br /&gt;
&lt;br /&gt;
# This clears the terminal/console window where python is run from.&lt;br /&gt;
def clrscn&amp;#40;&amp;#41;&amp;#58;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; print&amp;#40;os.system&amp;#40;'clear'&amp;#41;, chr&amp;#40;13&amp;#41;, &amp;quot;&amp;nbsp; &amp;quot;, chr&amp;#40;13&amp;#41;,&amp;#41;&lt;br /&gt;
&lt;br /&gt;
# This does a beep first followed by a clear screen.&lt;br /&gt;
def both&amp;#40;&amp;#41;&amp;#58;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; beep&amp;#40;&amp;#41;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; clrscn&amp;#40;&amp;#41;&lt;br /&gt;
# Beep and clear screen function end.&lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
That`s all there is to it... &lt;img src=&quot;images/smiles/icon_smile.gif&quot; alt=&quot;Smile&quot; border=&quot;0&quot; /&gt;</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=93731#93731</comments>
                                        <author>Bazza</author>
                                        <pubDate>Mon Oct 11, 2010 9:08 pm</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=93731#93731</guid>
                                      </item></channel></rss>