Strange effect with import

Jens Thoms Toerring jt at
Thu Dec 20 23:52:24 CET 2012

Thanks a lot to all three of you: that helped me understand
the errors of my ways! You just saved me a few more hours
of head-scratching;-)

A few replies to the questions and comments by Steven:

Steven D'Aprano <steve+comp.lang.python at> wrote:
> On Thu, 20 Dec 2012 20:39:19 +0000, Jens Thoms Toerring wrote:
> > and my expectation was that the static variable 'r' of class R 

> The terminology we prefer here is "class attribute", not "static 
> variable". Attributes are always assigned in dynamic storage, whether 
> they are per-instance or on the class.

I'm comimg from C/C++ and that's were my terminology is from,
I know I still have to learn a lot more about Python;-)

<good advice snipped>

> > In my "real" code it's unfortunately not
> > possible to pass that number to whatever is going to use it in the
> >  other file, I have to simulate a kind of global variable
> > shared between different files.

> Well, I find that hard to believe. "Not convenient"? I could believe 
> that. "Difficult"? Maybe. "Tricky"? I could even believe that. But "not 
> possible"? No, I don't believe that it is impossible to pass variables 
> around as method arguments.

You are rather likely right and I probably should have written:
"I don't see any way to pass that variable to the object that
is supposed to use it". Perhaps you have an idea how it could
be done correctly when I explain the complete picture: I'm
writing a TCP server, based on SocketServer:

 server = SocketServer.TCPServer((, 12345), ReqHandler)

where ReqHandler is the name of a class derived from

 class ReqHandler(SocketServer.BaseRequestHandler):

A new instance of this class is gernerated for each connection
request to the server. In the call that creates the server I can
only specify the name of the class but no arguments to be passed
to it on instantiation - at least I found nothing in the docu-
mentation. On the other hand I need to get some information into
this class and thus the only idea I came up with was to use some
kind of global variable for the purpose. Perhaps there's a much
better way to do that but I haven't found one yet. Or perhaps it
is an omission in the design of SocketServer or (more likely) my
mis-understanding of the documentation (as I wrote I'm relatively
new to Python).
                  Thnak you and best regards, Jens
  \   Jens Thoms Toerring  ___      jt at

More information about the Python-list mailing list