Lazy Python usage (hack request)
Aahz Maruch
aahz at panix.com
Sat Dec 30 12:10:15 EST 2000
In article <Pine.LNX.4.10.10012301443330.13756-100000 at kev.ioc.ee>,
Pearu Peterson <pearu at ioc.ee> wrote:
>
>Is it possible to achive the following behavior in Python?
>
>>>> import lazy
>>>> a = b
>No name 'b' defined, using default 777
>>>> print a
>777
>
>Note that changing the python session above is not an option. (Also 'No'
>for the answer;-)
Well, if you're going to stick to it not being an option to make any
changes, the answer is "no". However, you can make a little hack that
*does* work:
>>> from lazy import lazy
>>> a = lazy.b
No name 'b' defined, using default 777
>>> print a
777
Inside lazy.py, you define a class called lazy with a __getitem__()
method.
--
--- Aahz (Copyright 2000 by aahz at pobox.com)
Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6
Ninth Virtual Anniversary: Tomorrow!
More information about the Python-list
mailing list