Re: Costly object creation (was : Having Trouble with Scoping Rules)
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Costly object creation (was : Having Trouble with Scoping Rules)

From: bruno at modulix <onurb@xiludom.gro>
Date: Tue Jan 31 2006 - 10:44:28 CET

Charles Krug wrote:
> List:
>
> I've a module that's not doing what I expect. My guess is that I don't
> quite understand the scoping rules the way I should.
>
> I have an object that's costly to create. My thought was to create it
> at the module level like this:

(snip)

> What's the correct way to do this?
>
See other answers in this thread for how to solve the UnboundLocalError
problem.

Now about your *real* problem - which is nothing new -, you may want to
read about some known solutions:

http://en.wikipedia.org/wiki/Singleton_pattern
http://en.wikipedia.org/wiki/Proxy_pattern
http://en.wikipedia.org/wiki/Lazy_initialization
http://en.wikipedia.org/wiki/Memoization

HTH

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb@xiludom.gro'.split('@')])"
Received on Tue Feb 7 20:19:27 2006