<div class="gmail_quote">On Mon, Nov 24, 2008 at 10:00 AM, Peter van der Does <span dir="ltr">&lt;<a href="mailto:peter@avirtualhome.com">peter@avirtualhome.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I wrote my 1st Python program and it works as I want it to work but<br>
,IMHO, it looks horrible.</blockquote><div><br></div><div>Nothing to be ashamed of, unless you don&#39;t mind it looking horrible. The fact that you want a clean program is a good sign!</div><div>&nbsp;</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
&lt;snip&gt;</blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
Why I think it looks horrible:<br>
Everything is in main(), I would like to use functions but ran into<br>
problems with the scope of my variables.<br>
The CLI arguments check is just a bunch of IF&#39;s</blockquote><div><br></div><div>You would probably benefit from using a class then (especially if you have worries about your &quot;main&quot; program looking clean).</div>
<div><br></div><div>You can create global class variables that each of the methods/functions have access to with the self. - for instance</div><div><br></div><div><div>In [11]: class IP:</div><div>&nbsp;&nbsp; ....: &nbsp; &nbsp; address = &quot;<a href="http://192.168.1.1">192.168.1.1</a>&quot;</div>
<div>&nbsp;&nbsp; ....: &nbsp; &nbsp; def printAddress(self):</div><div>&nbsp;&nbsp; ....: &nbsp; &nbsp; &nbsp; &nbsp; print self.address</div><div>&nbsp;&nbsp; ....:</div><div>&nbsp;&nbsp; ....:</div><div><br></div><div>In [12]: x = IP()</div><div><br></div><div>In [13]: x.printAddress()</div>
<div><a href="http://192.168.1.1">192.168.1.1</a></div><div>---</div><div><br></div><div>Then you just declare a new instance of your class (see In[12]) and you have access to all its methods and variables;</div><div><br>
</div><div><div>In [15]: x.address = &quot;<a href="http://127.0.0.1">127.0.0.1</a>&quot;</div><div><br></div><div>In [16]: x.printAddress()</div><div><a href="http://127.0.0.1">127.0.0.1</a></div></div></div><div>&nbsp;</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Is this the place where somebody could go over my program and give<br>
some pointers on how to improve the structure or is there a forum out<br>
on the Net that can help me out.</blockquote><div><br></div><div>I don&#39;t know about anyone else, but I suspect most people are at least as busy as myself, but perfectly willing to help answer your questions, but I doubt anyone has the time (even if they want) to re-write your program /for/ you, but we&#39;ll be glad to help if you get stuck on a problem (or even need pointers on where else to look, if Google or your favourite search engine fails to turn up any information)</div>
<div><br></div><div>Using a class should really help clean up your program and help eliminate your scope problems. Here&#39;s a nifty little tutorial on python classes:</div><div><a href="http://www.diveintopython.org/object_oriented_framework/defining_classes.html">http://www.diveintopython.org/object_oriented_framework/defining_classes.html</a><br>
</div><div><br></div><div>Give classes a try and see if helps. If you&#39;re still having issues or you don&#39;t understand something, feel free to ask!</div><div><br></div><div>HTH,</div><div>Wayne</div></div>