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



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('@')])"
.