Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35239
| From | jt@toerring.de (Jens Thoms Toerring) |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Strange effect with import |
| Date | 2012-12-20 22:52 +0000 |
| Organization | Freie Universitaet Berlin |
| Message-ID | <ajhj58Ffv64U1@mid.uni-berlin.de> (permalink) |
| References | <ajhbbnFe4q1U1@mid.uni-berlin.de> <50d38d78$0$29967$c3e8da3$5496439d@news.astraweb.com> |
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@pearwood.info> 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((192.168.1.10, 12345), ReqHandler)
where ReqHandler is the name of a class derived from
SocketServer.BaseRequestHandler
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@toerring.de
\__________________________ http://toerring.de
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Strange effect with import jt@toerring.de (Jens Thoms Toerring) - 2012-12-20 20:39 +0000
Re: Strange effect with import Dave Angel <d@davea.name> - 2012-12-20 15:59 -0500
Re: Strange effect with import Peter Otten <__peter__@web.de> - 2012-12-20 22:11 +0100
Re: Strange effect with import Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-20 22:13 +0000
Re: Strange effect with import jt@toerring.de (Jens Thoms Toerring) - 2012-12-20 22:52 +0000
Re: Strange effect with import Terry Reedy <tjreedy@udel.edu> - 2012-12-20 19:54 -0500
Re: Strange effect with import jt@toerring.de (Jens Thoms Toerring) - 2012-12-21 01:12 +0000
Re: Strange effect with import Hans Mulder <hansmu@xs4all.nl> - 2012-12-21 01:54 +0100
Re: Strange effect with import jt@toerring.de (Jens Thoms Toerring) - 2012-12-21 01:25 +0000
Re: Strange effect with import jt@toerring.de (Jens Thoms Toerring) - 2012-12-21 15:52 +0000
csiph-web