J schrieb:
On Mon, Dec 7, 2009 at 16:13, J <[email protected]> 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 osA 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... 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 in myclass.os.walk(args) is that correct?
It is correct in the sense that it works, but it is by no means good practice.
How about if I have two classes in sysinfo.py and want to import os globally for BOTH classes to use? Same thing?
import os class A(): ... class B(): ... That's it. Diez -- http://mail.python.org/mailman/listinfo/python-list
