Killin' Newbie question
Ken Seehof
kens at sightreader.com
Mon Feb 28 12:07:47 EST 2000
Gregoire Welraeds wrote:
> I can't access the __init__ method outside of the object, so the
> following is disallowed :
> ----
> class huh():
> def __init(self):
> [some initialisation]
>
> ough= huh()
>
> [some code]
>
> ough.__init__()
> ----
>
> Right ?
> The following should be allowed ?
>
> class huh():
> def __init__(self):
> [some initialisation]
>
> def ReInit(self):
> self.__init__()
>
> ough= huh()
> [some code]
> ough.ReInit()
>
> Do I have to rewrite the __init__ function in the ReInit() or the call to
> the init() function inside the ReInit is enough ?
> Isn't there a better way to do this kind of job, i mean in a OOP point of
> view.
Since the previous reply answers your first question, I'll talk aboutprogramming
style. I would tend to write a ReInit function since
__init__ really means "called when you create the object". However,
there is nothing illegal about calling __init__ directly.
class huh:
def __init__(self):
# some one-time initialization code
print "spammity"
self.ReInit()
def ReInit(self):
# some code
print "spam"
>>> h = huh()
spammity
spam
>>> h.ReInit()
spam
The only time __init__ is usually called is from a derived object:
class what(huh):
def __init__(self):
huh.__init__(self)
# more initialization for what
> Other little question, what about the following (regarding another remark
> posted before) :
>
> def __init__(this):
Legal, but don't do that. People will think you are a C programmer :-) Ack!
> --
> Life is not fair
> But the root password helps
> --
>
> Gregoire Welraeds
> greg at perceval.be
> Perceval Development team
> -------------------------------------------------------------------------------
> Perceval Technologies sa/nv Tel: +32-2-6409194
> Rue Tenbosch, 9 Fax: +32-2-6403154
> B-1000 Brussels general information: info at perceval.net
> BELGIUM technical information: helpdesk at perceval.net
> URL: http://www.perceval.be/
> -------------------------------------------------------------------------------
More information about the Python-list
mailing list