Module imports during object instantiation
Neil Cerutti
horpner at yahoo.com
Wed Aug 15 14:42:23 EDT 2007
On 2007-08-15, Ritesh Raj Sarraf <rrs at researchut.com> wrote:
> Neil Cerutti wrote:
>
>>>
>>> Doesn't __init__ get called automatically ?
>>
>> It gets called automatically when you construct an instance of
>> the class in which it's defined.
>
> I am a little confused by your statements now.
>
> In my earlier posts in the same thread, I gave some code example which was
> something like this:
>
> class Log:
> def __init__():
> if os.name == 'posix':
> try:
> import foobar
> except ImportError, e:
> print >> sys.stderr, e
>
> (Sorry for the bad indentation)
>
> Now, what do you mean here by "construct an instance of the class in which
> it is defined" ?
>
> __init__() _is_ defined in the Log class and I try to create an instance of
> the class Log as:
>
> log = Log()
>
> Assuming it is run on a box which is POSIX compliant, the
> try/import should fail and I should see an error message
> because there is no module named foobar. But I don't see that.
> And this is what exactly I wanted to get clarified in this
> whole thread. (But still haven't got a clear answer to a
> Yes/No).
>
> Or am I terribly missing something that you are trying to tell ?
I didn't see log = Log() in your example. Sorry for the
excursion.
Are you sure os.name is 'posix' on your system?
--
Neil Cerutti
We've got to pause and ask ourselves: How much clean air do we really need?
--Lee Iacocca
More information about the Python-list
mailing list