Re: question about imports in a class

2009-12-07 Thread r0g
Diez B. Roggisch wrote: > J schrieb: >> On Mon, Dec 7, 2009 at 16:57, Diez B. Roggisch >> wrote: >> if I put the import at the beginning of the class, it just dawned on me that perhaps I still have to explicitly call the function by class: > I'm not annoyed. I just wonder from what

Re: question about imports in a class

2009-12-07 Thread Diez B. Roggisch
J schrieb: On Mon, Dec 7, 2009 at 16:57, Diez B. Roggisch wrote: if I put the import at the beginning of the class, it just dawned on me that perhaps I still have to explicitly call the function by class: sysinfo.py class myclass(): import os def findDMIDecode(self): for r,d,f i

Re: question about imports in a class

2009-12-07 Thread Steven D'Aprano
On Mon, 07 Dec 2009 16:53:46 -0500, J wrote: > A little more education and playing around and I'm still not quite sure > how to do this... > > for the class i'm writing, I want to import os, sys and wmi globally for > the class... The best advice is Do Not Do It That Way. Just do your imports at

Re: question about imports in a class

2009-12-07 Thread Rhodri James
On Mon, 07 Dec 2009 22:18:49 -, J wrote: On Mon, Dec 7, 2009 at 16:57, Diez B. Roggisch wrote: if I put the import at the beginning of the class, it just dawned on me that perhaps I still have to explicitly call the function by class: sysinfo.py class myclass(): import os def f

Re: question about imports in a class

2009-12-07 Thread J
On Mon, Dec 7, 2009 at 16:57, Diez B. Roggisch wrote: >> if I put the import at the beginning of the class, it just dawned on >> me that perhaps I still have to explicitly call the function by class: >> >> sysinfo.py >> >> class myclass(): >>    import os >>    def findDMIDecode(self): >>        

Re: question about imports in a class

2009-12-07 Thread Rhodri James
On Mon, 07 Dec 2009 21:13:25 -, J wrote: Just a little newbie confusion about OS imports... Why does this give me an error: It's generally helpful to say *what* error you get, including the traceback. Fortunately the source code is enough this time. class Windows: def __init__

Re: question about imports in a class

2009-12-07 Thread Diez B. Roggisch
J schrieb: On Mon, Dec 7, 2009 at 16:13, J wrote: But why does importing in the init not make os available to every other function in the class? Do I have to import OS into every function like this: class ClassA(): def func1(self): import os def func2(self): import os

Re: question about imports in a class

2009-12-07 Thread J
On Mon, Dec 7, 2009 at 16:13, J wrote: > But why does importing in the init not make os available to every > other function in the class?  Do I have to import OS into every > function like this: > > class ClassA(): > >    def func1(self): >        import os > >    def func2(self): >        import

Re: question about imports in a class

2009-12-07 Thread Diez B. Roggisch
J schrieb: Just a little newbie confusion about OS imports... Why does this give me an error: class Windows: def __init__(self): ''' Constructor ''' import os self.dmidecodePath="" #final path to dmidecode binary def parseDMI(self): # Fi

question about imports in a class

2009-12-07 Thread J
Just a little newbie confusion about OS imports... Why does this give me an error: class Windows: def __init__(self): ''' Constructor ''' import os self.dmidecodePath="" #final path to dmidecode binary def parseDMI(self): # First, find dmi