Short sections of code are not where classes shine. <br><br>Classes become much more valuable when you start to get a lot of hairy details you need to pass around. For your code, for instance, you could pass in the whole registry key you want, and have out pop a RegKey object.
<br><br>This would be say, usable in a system where you needed to do several operations on this object. If you were accessing multiple registry keys for instance, it would probably be nice to make a RegKey class that could be created with a handy method. If you were only accessing one key one time, a simple routine will serve you well.
<br><br>Realms where classes are almost always used<br>Simulations, GUI elements, business systems of any size, many parsers, especially XML and HTML parsers.<br><br>Realms where they&#39;re used much less:<br>Basic text processing, system administration tasks, simple database systems, and number crunching apps.
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --Michael<br><br clear="all"><br>-- <br>Michael Langford<br>Phone: 404-386-0495<br>Consulting: <a href="http://www.TierOneDesign.com/">http://www.TierOneDesign.com/</a><br>Entertaining: <a href="http://www.ThisIsYourCruiseDirectorSpeaking.com">
http://www.ThisIsYourCruiseDirectorSpeaking.com</a>
<br><br><div><span class="gmail_quote">On 9/17/07, <b class="gmail_sendername">Eric Lake</b> &lt;<a href="mailto:ericlake@ubuntu.com">ericlake@ubuntu.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I am still trying to understand when to use a class and when not to. All<br>of the coding that I have done in the past (Python, Perl) has been<br>procedural / functional. I would really like to do more OOP but I am not<br>
really sure when I need it.<br><br>I have the following code. Is there any way that it would benefit from<br>using a class?<br><br>&lt;code&gt;<br><br>#!/usr/bin/env python<br><br>import string<br>import _winreg<br>import sys
<br><br>compName = sys.argv[1]<br><br>x = _winreg.ConnectRegistry(compName,_winreg.HKEY_LOCAL_MACHINE)<br>y = _winreg.OpenKey(x,<br>r&quot;SOFTWARE\Intel\LANDesk\VirusProtect6\CurrentVersion&quot;)<br>avParent = _winreg.QueryValueEx(y,&quot;Parent&quot;)[0]
<br><br>_winreg.CloseKey(y)<br><br>print &quot;Computer: %s \tAV Parent: %s&quot; % (compName,avParent)<br><br>&lt;/code&gt;<br><br><br>--<br><br>Thanks<br>Eric Lake<br><br>-----BEGIN PGP SIGNATURE-----<br>Version: GnuPG 
v1.4.6 (GNU/Linux)<br><br>iQEVAwUBRu6u2ZLZLpR+JU3MAQp0Dgf/cMXUpmBnVM3NPQu6b2LVwEN/L5+DG0hn<br>r3oyyVr56EIz04zl6fRqOk4NPkW0d0y5x2uvwWMCgvy64gyd9cHSrwCPxorCcf1j<br>/71QhXA0Nx44mwJK6ahCatcfimzUF1MeykOX0oxcaAP26JDtV7eF0jYjzizsEzmE
<br>Q+2JlWzlOKrljxKL1zJLPepzubwoWFIYFmlXfYdbk2HkMCPmzPfAipEZW8WPj5xU<br>Fu1lGWEuODSEn/+d4X6tPNlJLOAxgL01IPPUZZSso6gfjlLDHYVPTYTEUDgZIrLD<br>XPuFpNT7tT8jQWZKg6OFjFS2P6/LVc02AYskXjegmEyMfNDZ27qLMw==<br>=9N/n<br>-----END PGP SIGNATURE-----
<br><br>_______________________________________________<br>Tutor maillist&nbsp;&nbsp;-&nbsp;&nbsp;<a href="mailto:Tutor@python.org">Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor
</a><br><br></blockquote></div><br>