problem with Python class creating
timaranz at gmail.com
timaranz at gmail.com
Thu Oct 18 15:48:52 EDT 2007
On Oct 19, 8:22 am, dmitrey <dmitrey.kros... at scipy.org> wrote:
> Hi all,
> I have the code like this one:
>
> from myMisc import ooIter
> class MyClass:
> def __init__(self): pass
> iterfcn = lambda *args: ooIter(self) # i.e pass the class instance
> to other func named ooIter
> field2 = val2
> field3 = val3 # etc
>
> So it yields "global name 'self' is not defined", that is true. How
> could I handle the situation?
>
> Currently I do (and it works, but give me some troubles - I should
> call MyClass.__init__ for each children class, and there are lots of
> those ones)
>
> class MyClass:
> def __init__(self):
> iterfcn = lambda *args: ooIter(self) # i.e pass the class
> instance to other func named ooIter
> field2 = val2
> field3 = val3 # etc
>
> I suspect it has better solution, is it?
> Thank you in advance, Dmitrey
without having tested - I think this should work for you:
from myMisc import ooIter
class MyClass:
def __init__(self): pass
iterfcn = lambda self: ooIter(self)
More information about the Python-list
mailing list