<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>eTechTips &#187; Python</title>
	<atom:link href="http://www.etechtips.com/articles/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.etechtips.com</link>
	<description>Your Technical resource</description>
	<lastBuildDate>Wed, 01 Feb 2012 21:38:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Python: if/else Statements</title>
		<link>http://www.etechtips.com/2012/01/20/python-ifelse-statements/</link>
		<comments>http://www.etechtips.com/2012/01/20/python-ifelse-statements/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 16:25:47 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=601</guid>
		<description><![CDATA[There comes a time when you are writing a program and you need to branch based on input to a program. This is the format of the if/else statement in Python. if &#60;some true/false statement&#62; : &#60;some statements that run if the if statement is true&#62; else: &#60;some other statements that run if the if [...]]]></description>
			<content:encoded><![CDATA[<p>There comes a time when you are writing a program and you need to branch based on input to a program.<br />
This is the format of the if/else statement in Python.  </p>
<pre>
if &lt;some true/false statement&gt; :
  &lt;some statements that run if the if statement is true&gt;
else:
  &lt;some other statements that run if the if statement are false&gt;
</pre>
<p>There may be times when you have more than one value set to test against.  In that case you can write a many if/else<br />
statements but you can chain the if/else statements with an elif.  So the chain becomes if/elif/else.</p>
<pre>
if x < 5:
  &lt;some statements that run if the if statement is true&gt;
elif x > 5 and x < 10:
  &lt;some statements that run if the elif statement is true&gt;
else:
  &lt;if none of the if checks are true, run the statements in the else case.&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2012/01/20/python-ifelse-statements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python: Allow for empty if else blocks</title>
		<link>http://www.etechtips.com/2012/01/20/python-allow-for-empty-if-else-blocks/</link>
		<comments>http://www.etechtips.com/2012/01/20/python-allow-for-empty-if-else-blocks/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 16:15:28 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=605</guid>
		<description><![CDATA[I was toying with a prime number finder and was creating a set of if/else statements for a horribly failed attempt and wanted to skip to the next number on any of the if statements that were true. I didn&#8217;t want to put an empty print statement as that would disrupt the output I was [...]]]></description>
			<content:encoded><![CDATA[<p>I was toying with a prime number finder and was creating a set of if/else statements for a horribly failed attempt<br />
and wanted to skip to the next number on any of the if statements that were true.  I didn&#8217;t want to put an empty print<br />
statement as that would disrupt the output I was expecting from the program.  I found the pass statement.<br />
Here is an example from my not very successful attempt at finding primes:</p>
<pre>
if inp > 2 and inp % 2 == 0:
  pass
elif inp > 3 and inp % 3 == 0:
  pass
elif inp > 7 and inp % 7 == 0:
  pass
elif inp > 9 and inp % 9 == 0:
  pass
else:
  print inp, " is a prime"
</pre>
<p>Yes, this does not accurately find the primes, but it would skip any number that is divisible by 2,3,5,7, or 9.  And<br />
anything that does not match this will be listed as a prime, this is incorrect and would be made to add new elif<br />
statements as each prime was found.   </p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2012/01/20/python-allow-for-empty-if-else-blocks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to exit python script</title>
		<link>http://www.etechtips.com/2011/08/23/how-to-exit-python-script/</link>
		<comments>http://www.etechtips.com/2011/08/23/how-to-exit-python-script/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 13:43:50 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Utilities]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=154</guid>
		<description><![CDATA[When I was trying to terminate a python script after a failure, I tried to find the nicest way to exit. The sys.exit() command provided by importing the sys library was what I found. The function can take an optional numeric argument, usually in the range of 0-127, and with no argument it returns 0. [...]]]></description>
			<content:encoded><![CDATA[<p>When I was trying to terminate a python script after a failure, I tried to find the nicest way to exit.  The sys.exit() command provided by importing the sys library was what I found.</p>
<p>The function can take an optional numeric argument, usually in the range of 0-127, and with no argument it returns 0.  The return code is passed back to the Operating System.</p>
<pre>
import sys
sys.exit(1)
</pre>
<p>When exit returns a non-zero value, it is considered an error.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/08/23/how-to-exit-python-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gallery of Hello World!</title>
		<link>http://www.etechtips.com/2011/08/04/gallery-of-hello-world/</link>
		<comments>http://www.etechtips.com/2011/08/04/gallery-of-hello-world/#comments</comments>
		<pubDate>Thu, 04 Aug 2011 15:14:39 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=324</guid>
		<description><![CDATA[Here is a list of the Hello World Programs for different languages: C #include int main() { printf("Hello World!"); } C++ #include int main() { cout &#60;&#60; "Hello World!" &#60;&#60; endl; } C# public class HelloWorld public static void Main() { System.Console.WriteLine("Hello World!"); } Java class HelloWorld { static void main(String[] args) { System.out.println("Hello World!"); [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a list of the Hello World Programs for different languages:</p>
<p>C</p>
<pre>#include
int main()
{
printf("Hello World!");
}</pre>
<p>C++</p>
<pre>#include
int main()
{
cout &lt;&lt; "Hello World!" &lt;&lt; endl;
}</pre>
<p>C#</p>
<pre>public class HelloWorld
  public static void Main()
  {
    System.Console.WriteLine("Hello World!");
  }</pre>
<p>Java</p>
<pre>class HelloWorld {
static void main(String[] args)
{
System.out.println("Hello World!");
}</pre>
<p>SHELL</p>
<pre>echo "Hello World"</pre>
<p>Python</p>
<pre>print "Hello World!\n"</pre>
<p>Ruby</p>
<pre>puts "Hello World!"</pre>
<p>Perl</p>
<pre>print "Hello World!\n";</pre>
<p>PHP</p>
<pre>  &lt;?php
    print "Hello World!";
  ?&gt;</pre>
<p>This is the simplest form of Hello World for most of these languages.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/08/04/gallery-of-hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python: AttributeError: &#8216;getopt&#8217; module has no attribute &#8216;GetoptError&#8217;</title>
		<link>http://www.etechtips.com/2010/07/28/python-attributeerror-getopt-module-has-no-attribute-getopterror/</link>
		<comments>http://www.etechtips.com/2010/07/28/python-attributeerror-getopt-module-has-no-attribute-getopterror/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 16:31:22 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/2010/07/28/python-attributeerror-getopt-module-has-no-attribute-getopterror/</guid>
		<description><![CDATA[So I was figuring out how to parse command line arguments with python and using the getopt module with the following code #!/usr/bin/env python import sys import getopt def main(argv): infile = "some.xml" try: opts,args = getopt.getopt(argv,"hi:d",["help","infile="] except getopt.GetoptError: usage() sys.exit(2) if __name__ == "__main__": main(sys.argv[1:]) And I was getting the following error: AttributeError: &#8216;getopt&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>So I was figuring out how to parse command line arguments with python and using the getopt module with the following code</p>
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>
#!/usr/bin/env python
import sys
import getopt

def main(argv):
   infile = "some.xml"
   try:
      opts,args = getopt.getopt(argv,"hi:d",["help","infile="]
   except getopt.GetoptError:
      usage()
      sys.exit(2)

if __name__ == "__main__":
    main(sys.argv[1:])
</code></pre>
<p>And I was getting the following error:</p>
<p>AttributeError: &#8216;getopt&#8217; module has no attribute &#8216;GetoptError&#8217;</p>
<p>So my first problem was that I had named my script getopt.py and after renaming the script, I got the same error.  Well you now need to remove the getopt.pyc file that was generated from your earlier running of the poorly named script. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2010/07/28/python-attributeerror-getopt-module-has-no-attribute-getopterror/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

