On Saturday, October 19, 2013 2:44:55 PM UTC-7, Peter Cacioppi wrote:
> Is the following considered poor Python form?
> 
> 
> 
> class Foo (object) :
> 
>     _lazy = None
> 
>     def foo(self, x) :
> 
>         _lazy = _lazy or self.get_something(x)
> 
>     def get_something(self, x) :
> 
>         # doesn't really matter
> 
> 
> 
> I like this idiom for certain situations, just wondering if it will raise the 
> hackles of other Pythonistas. 
> 
> 
> 
> I use this idiom sparingly, but sometimes it just fits the task at hand, I 
> hear Guidos voice saying "use the Force" in my ear, etc.

To be clear, I use this when I'm subclassing something and don't need to do 
anything with the _lazy other than set it to None in the __init__. I like this 
idiom because it removes the risk of miscalling the parent __init__, and it's 
also quick and easy to code.

Yes there is a class member I am creating, but each instance has a distinct 
member. (In other words, I'm an adult, I tested it and it works, but I couldn't 
find anything in the Google indicating what the collective reaction would be 
from Pythonistan)
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to