Re: Module imports during object instantiation

2007-08-16 Thread Ritesh Raj Sarraf
Steve Holden wrote: > Ritesh Raj Sarraf wrote: >> On Aug 16, 12:16 am, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: >>> On Aug 15, 11:42 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: >>> > [...] >> Oops!!! Looks like I completely missed this. It _did_ print the error >> message. >> Apologies to all

Re: Module imports during object instantiation

2007-08-15 Thread Steve Holden
Ritesh Raj Sarraf wrote: > On Aug 16, 12:16 am, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: >> On Aug 15, 11:42 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: >> [...] > Oops!!! Looks like I completely missed this. It _did_ print the error > message. > Apologies to all for not keeping a close eye on

Re: Module imports during object instantiation

2007-08-15 Thread Ritesh Raj Sarraf
On Aug 16, 12:16 am, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: > On Aug 15, 11:42 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: > > > On 2007-08-15, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: > > > Or am I terribly missing something that you are trying to tell ? > > > I didn't see log = Log() in

Re: Module imports during object instantiation

2007-08-15 Thread Ritesh Raj Sarraf
On Aug 15, 11:42 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: > On 2007-08-15, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: > > 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

Re: Module imports during object instantiation

2007-08-15 Thread Neil Cerutti
On 2007-08-15, Ritesh Raj Sarraf <[EMAIL PROTECTED]> 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

Re: Module imports during object instantiation

2007-08-15 Thread Ritesh Raj Sarraf
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 s

Re: Module imports during object instantiation

2007-08-14 Thread Neil Cerutti
On 2007-08-14, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: > Neil Cerutti wrote: > >> If you want an import inside an __init__ to run, you must call >> the __init__ function that contains it. > > Doesn't __init__ get called automatically ? It gets called automatically when you construct an instan

Re: Module imports during object instantiation

2007-08-14 Thread Ritesh Raj Sarraf
Neil Cerutti wrote: > If you want an import inside an __init__ to run, you must call > the __init__ function that contains it. Doesn't __init__ get called automatically ? I thought __init__ was required to be called explicitly only when you were doing inheritance and wanted to pass separate value

Re: Module imports during object instantiation

2007-08-14 Thread Neil Cerutti
On 2007-08-14, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: > Bruno Desthuilliers wrote: > What's leading you to conclude the import isn't being executed? You realise, I trust, that the module's code will only be executed on the first call to __init__()? >>> >>> Well. Putting i

Re: Module imports during object instantiation

2007-08-14 Thread Ritesh Raj Sarraf
Bruno Desthuilliers wrote: >>> What's leading you to conclude the import isn't being executed? You >>> realise, I trust, that the module's code will only be executed on the >>> first call to __init__()? >>> >> >> Well. Putting it in a "try" inside __init__() doesn't do anything. > > This would b

Re: Module imports during object instantiation

2007-08-14 Thread Bruno Desthuilliers
Ritesh Raj Sarraf a écrit : > Steve Holden wrote: (snip) >> What's leading you to conclude the import isn't being executed? You >> realise, I trust, that the module's code will only be executed on the >> first call to __init__()? >> > > Well. Putting it in a "try" inside __init__() doesn't do an

Re: Module imports during object instantiation

2007-08-14 Thread Bruno Desthuilliers
Ritesh Raj Sarraf a écrit : > Bruno Desthuilliers wrote: > >> Ritesh Raj Sarraf a écrit : >>> if lock is None or lock != 1: >>> self.DispLock = False >>> else: >>> self.DispLock = threading.Lock() >>> self.lock = True >>> >>> if os.name =

Re: Module imports during object instantiation

2007-08-14 Thread Bruno Desthuilliers
Ritesh Raj Sarraf a écrit : > Bruno Desthuilliers wrote: > >> Ritesh Raj Sarraf a écrit : >> >> The initializer will be called *each time* you instanciate the class. >> And nothing prevents client code from calling it explicitelly as many >> times as it wants - ok, this would be rather strange, b

Re: Module imports during object instantiation

2007-08-13 Thread Ritesh Raj Sarraf
Steve Holden wrote: > Ritesh Raj Sarraf wrote: >> class Log: >> >> def __init__(self, verbose, lock = None): >> >> if verbose is True: >> self.VERBOSE = True >> else: self.VERBOSE = False >> > Better: > > self.VERBOSE = verbose > > or, if you suspect verbose mi

Re: Module imports during object instantiation

2007-08-13 Thread Ritesh Raj Sarraf
Bruno Desthuilliers wrote: > Ritesh Raj Sarraf a écrit : > > The initializer will be called *each time* you instanciate the class. > And nothing prevents client code from calling it explicitelly as many > times as it wants - ok, this would be rather strange, but this is still > technically possi

Re: Module imports during object instantiation

2007-08-13 Thread Ritesh Raj Sarraf
Bruno Desthuilliers wrote: > Ritesh Raj Sarraf a écrit : >> >> if lock is None or lock != 1: >> self.DispLock = False >> else: >> self.DispLock = threading.Lock() >> self.lock = True >> >> if os.name == 'posix': >>self.platf

Re: Module imports during object instantiation

2007-08-13 Thread Steve Holden
Ritesh Raj Sarraf wrote: > Hi, > > I've been very confused about why this doesn't work. I mean I don't see any > reason why this has been made not to work. > > class Log: > > def __init__(self, verbose, lock = None): > > if verbose is True: > self.VERBOSE = True >

Re: Module imports during object instantiation

2007-08-13 Thread Bruno Desthuilliers
Ritesh Raj Sarraf a écrit : > On Aug 11, 3:17 am, James Stroud <[EMAIL PROTECTED]> wrote: >> You do realize your import statement will only be called for nt and dos >> systems don't you? >> > > Yes. I would like to load a Windows Python Module (which is, say a > specific implementation for Windows

Re: Module imports during object instantiation

2007-08-13 Thread Bruno Desthuilliers
Ritesh Raj Sarraf a écrit : > Hi, > > I've been very confused about why this doesn't work. I mean I don't see any > reason why this has been made not to work. > > class Log: > > def __init__(self, verbose, lock = None): > > if verbose is True: Don't use an identity test here. There

Re: Module imports during object instantiation

2007-08-11 Thread Ritesh Raj Sarraf
On Aug 11, 3:17 am, James Stroud <[EMAIL PROTECTED]> wrote: > You do realize your import statement will only be called for nt and dos > systems don't you? > Yes. I would like to load a Windows Python Module (which is, say a specific implementation for Windows only) in such a condition where I find

Re: Module imports during object instantiation

2007-08-10 Thread James Stroud
Ritesh Raj Sarraf wrote: > Hi, > > I've been very confused about why this doesn't work. I mean I don't see any > reason why this has been made not to work. > > class Log: > > def __init__(self, verbose, lock = None): > > if verbose is True: > self.VERBOSE = True >

Module imports during object instantiation

2007-08-10 Thread Ritesh Raj Sarraf
Hi, I've been very confused about why this doesn't work. I mean I don't see any reason why this has been made not to work. class Log: def __init__(self, verbose, lock = None): if verbose is True: self.VERBOSE = True else: self.VERBOSE = False if lock is