[Tutor] question about importing threads

shawn bright nephish at gmail.com
Fri Feb 9 22:50:08 CET 2007

ok, i have started doing this with my 4000 + line file. So far its been
working out.
i have another question about it.

i have two classes in my program that use a global object that is a socket

global  my_sockobj
serverhost = 'mehost.com'
serverport = 9100
my_sockobj = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

then i use my_socket.recv to get stuff from the socket in one class
and my_socket.send to send stuff from another class.

is there something tricky about passing this as a global object to different
modules that would need to use it?
Or does this go along with what you wrote a while back about having classes
that depend on each other ?

One runs as a thread, the other responds to gui input.

thanks for any tips.


On 12/31/06, Alan Gauld <alan.gauld at btinternet.com> wrote:
> "shawn bright" <nephish at gmail.com> wrote
> > Yes, the thing is getting to be a pain to deal with at this size, i
> > am
> > in-process of splitting out the classes into their own files.
> One thing to watch is that while its easy and tempting to create
> one file per class it's often better to keep dependant classes
> together.
> In other words if class A can only be used together with class B
> then it is often better to keep A and B in the same module.
> Anyone who needs B can import the module and anyone who
> needs A needs B too so it saves them having to import two
> modules.
> As in all things in programming a little bit of thought is often
> better than the first "obvious" strategy. Grady Booch described
> the above strategy by saying that "the unit of reuse is the category"
> (which in his OO notation was a set of related classes) and in
> Python that means the module.
> Regards,
> Alan G.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070209/5329af12/attachment.htm 

More information about the Tutor mailing list