Newbie Question regarding __init__()
gagsl-py2 at yahoo.com.ar
Sat Aug 1 06:48:50 CEST 2009
En Sat, 01 Aug 2009 00:13:05 -0300, Nat Williams <nat.williams at gmail.com>
> One other thing. I'm a little confused by the first line of
> self.init_Pre() and self.init_Exec()
> I suspect this does not do what you think it does. init_Pre and
> will both be called by this expression (unless init_Pre throws an
> of course). You're not getting anything here that you wouldn't by just
> calling each method on a separate line, except just making it harder to
Well, perhaps Simon didn't grasp Python's syntax and semantics very well
yet, but his code would work as designed after fixing obvious errors:
"""default init method has the form
of init_Pre() and init_Exec
self.init_Pre() and self.init_Exec()
"""Always called before init_Exec()
if it returns false init_Exec is
"""Base __init__ code goes here and this is
only executed if init_Pre() returns true"""
"""Always called after the init_Pre() and
init_Pre might return False, in that case init_Exec would not be executed.
init_Post is always called. And that's exactly what the docstrings say.
I would use an `if` statement instead:
if self.init_Pre(): self.init_Exec()
and make init_Exec and init_Post not return anything if they have no
intrinsic meaning. And probably use better names. But basically the
structure is OK.
More information about the Python-list