Re: Costly object creation (was : Having Trouble with Scoping Rules)
- From: bruno at modulix <onurb@xxxxxxxxxxx>
- Date: Tue, 31 Jan 2006 10:44:28 +0100
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@xxxxxxxxxxx'.split('@')])"
.
- Follow-Ups:
- Re: Costly object creation (was : Having Trouble with Scoping Rules)
- From: Charles Krug
- Re: Costly object creation (was : Having Trouble with Scoping Rules)
- References:
- Having Trouble with Scoping Rules
- From: Charles Krug
- Having Trouble with Scoping Rules
- Prev by Date: finding the intersection of a list of Sets
- Next by Date: test whether 2 objects are equal
- Previous by thread: Re: Having Trouble with Scoping Rules
- Next by thread: Re: Costly object creation (was : Having Trouble with Scoping Rules)
- Index(es):