Yes, Mr Gauld, this is a help. Even though i am still newbie enough to take some time digesting it.<br><br>one last queston. if i have a class that i import as a module, say a script that emails me when something goes wrong.
<br>so i have a file called my_own_email.py and in it a class called MyOwnEmail. Now MyOwnEmail needs the smtplib module. Do i need to import it just for the my_own_email.py or do i need to import it in both that module and my program that calls it. ?
<br><br>thanks<br><br><br><div><span class="gmail_quote">On 2/9/07, <b class="gmail_sendername">ALAN GAULD</b> &lt;<a href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.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;">
<div><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;">
<span class="q">&gt; i have two classes in my program that use a global object <br>&gt; that is a socket connection.<br></span>&gt; ... code snipped<span class="q"><br>&gt; is there something tricky about passing this as a global object to 
<br>&gt; different modules that would need to use it?
<br><br></span>Whiler its possible to use a global in this way its usually better to <br>avoid global objects in a reusable component since otherwise it <br>might clash with another global that the reuser already has. Its much 
<br>better to use a parameter which can be provided by the user of the <br>classes. In this case the socklet becomesc a parameter.<br><br>A good place to put this parameter would be the init method of both <br>your classes, where they would store a reference to it as an internal 
<br>attribute. (remember that in Python all attributes are references so if <br>you pass the same socket to both constructors both classes will point <br>at the same socket).<br><br>This approach also allows the user of your classes to suvbstitute 
<br>any socketlike object that they mauy have, even their own bespoke <br>version if needed. That greatly increases the flexibility of your code.<span class="q"><br><br>&gt; Or does this go along with what you wrote a while back about 
<br>&gt; having
 classes that depend on each other ?<br><br></span>If you really must use a shared global then I would strongly consider <br>putting both classes, the global variable and an initialisation function <br>all in a single module. If however tyou can parameterise things as 
<br>described then you need to consider whether anyone would be <br>able to (and want to) use either of the classes without the other. <br>If you always need them as a pair they still should go in one module, <br>otherwise put them in separate modules.
<span class="q"><br><br>&gt; One runs as a thread, the other responds to gui input.<br><br></span>Does it respond to GUI input or just input? If it can be independant <br>of the GUI (and you should really try hard to make it so) then its 
<br>independant and best in its own module. The fact that the other runs <br>in a thred is fairly irrelevant to this discussion, the real issue is <br>whether it has hard coded dependencies on the other class. For <br>example does it instantiate a copy within
 its methods? (in which <br>case you must import the other module/class into this module) And <br>more especially does it take an instance as a parameter of a method?<br>(in which case the *re-user* must import the other module.) In the second 
<br>case I&#39;d say definitely put them in a single module, in the first case <br>consider it, but it&#39;s not essential.<br><br>I hope that makes sense,<br><br>Alan G.<span class="q"><br><br><br><div><span class="gmail_quote">
On 12/31/06, <b class="gmail_sendername">Alan Gauld</b> &lt;<a rel="nofollow" href="mailto:alan.gauld@btinternet.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">alan.gauld@btinternet.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;">
&quot;shawn bright&quot; &lt;<a rel="nofollow" href="mailto:nephish@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">nephish@gmail.com</a>&gt; wrote<br><br>&gt; Yes, the thing is getting to be a pain to deal with at this size, i
<br>&gt; am<br>&gt; in-process of splitting out the classes into their own files.
<br><br>One thing to watch is that while its easy and tempting to create<br>one file per class it&#39;s often better to keep dependant classes<br>together.<br>In other words if class A can only be used together with class B
<br>then it is often better to keep A and B in the same module.<br>Anyone who needs B can import the module and anyone who<br>needs A needs B too so it saves them having to import two<br>modules.<br><br>As in all things in programming a little bit of thought is often
<br>better than the first &quot;obvious&quot; strategy. Grady Booch described<br>the above strategy by saying that &quot;the unit of reuse is the category&quot;<br>(which in his OO notation was a set of related classes) and in
<br>Python that means the module.<br><br>Regards,<br><br>Alan G.<br><br><br>_______________________________________________<br>Tutor maillist&nbsp;&nbsp;-&nbsp;&nbsp;<a rel="nofollow" href="mailto:Tutor@python.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
Tutor@python.org</a><br><a rel="nofollow" href="http://mail.python.org/mailman/listinfo/tutor" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://mail.python.org/mailman/listinfo/tutor</a><br></blockquote></div><br>
</span></div><br></div></div><br>
                <hr size="1"> 
New Yahoo! Mail is the ultimate force in competitive emailing. Find out more at the <a href="http://uk.rd.yahoo.com/mail/uk/taglines/gmail_com/championships/games/*http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
Yahoo! Mail Championships</a>. Plus: play games and win prizes.</div></blockquote></div><br>