[Twisted-Python] Newbie question: How to reference the "__main__"

Uwe C. Schroeder uwe at oss4u.com
Sun Oct 3 22:29:01 EDT 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Just use a singleton design for your Configuration class

class Configuration:
	class __impl:
		def __init__(self):
			# do your stuff here
                        #
	

    	__instance = __impl()

    	def __getattr__(self,attr):
     	   return getattr(self.__instance,attr)

    	def __setattr__(self,attr,value):
     	   return setattr(self.__instance, attr, value)
	

whenever you instanciate Configuration the inner __impl instance will always 
be the same. Maybe I missed something above - just look up the singleton 
design in the python cookbook (activestate.com)

Hope that helps

UC


On Sunday 03 October 2004 07:16 pm, Iap, Singuan wrote:
> I have a work-around like this:
>
> import __main__
> __main__.config=Configuration()
>
> And  access it in other modules by:
>
> import __main__
> config=__main__.config
>
> But I don't think that is a good idea.
> There must be more simple and extensible way, I guess.
>
> Iap, Singuan
>
>
> -----Original Message-----
> From: twisted-python-bounces at twistedmatrix.com
> [mailto:twisted-python-bounces at twistedmatrix.com]On Behalf Of Yun Mao
> Sent: Friday, October 01, 2004 11:33 PM
> To: Twisted general discussion
> Subject: Re: [Twisted-Python] Newbie question: How to reference the
> "__main__"
>
>
> but the sys.argv[1:] is going to be twistd's argument, including
> "-noy","xxx.tac", etc. right? it isn't exactly what he wanted, is it?
>
> Yun
>
> On Fri, 1 Oct 2004, Itamar Shtull-Trauring wrote:
> > On Fri, 2004-10-01 at 05:40, Iap, Singuan wrote:
> > > In server.py
> > > ----------------------------------------
> > > config=Configuration()
> >
> > somewhere.MyObject.addConfig(config)
> >
> > and then MyObject can access the config.
> >
> >
> > _______________________________________________
> > Twisted-Python mailing list
> > Twisted-Python at twistedmatrix.com
> > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

- -- 
	UC

- --
Open Source Solutions 4U, LLC	2570 Fleetwood Drive
Phone:  +1 650 872 2425		San Bruno, CA 94066
Cell:   +1 650 302 2405		United States
Fax:    +1 650 872 2417
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFBYLVtjqGXBvRToM4RAlLWAKDSfoSU0vgN5WC0jc1R4EWkhCcEtgCg01DW
XdOI9yXBfld26J//pdFjBY0=
=Svl5
-----END PGP SIGNATURE-----





More information about the Twisted-Python mailing list