question about imports in a class
Rhodri James
rhodri at wildebst.demon.co.uk
Mon Dec 7 17:26:16 EST 2009
On Mon, 07 Dec 2009 22:18:49 -0000, J <dreadpiratejeff at gmail.com> wrote:
> On Mon, Dec 7, 2009 at 16:57, Diez B. Roggisch <deets at nospam.web.de>
> 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 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.
>
> So good practice (I'm doing this for real as well as for my own
> education) would be:
>
> sysinfo.py:
>
> import os
>
> class ClassA():
> sysinfo.os.walk()
>
> class ClassB():
> sysinfo.os.walk()
Nope. Good practice would be:
import os
class ClassA(object):
os.walk()
class ClassB(object):
os.walk()
--
Rhodri James *-* Wildebeest Herder to the Masses
More information about the Python-list
mailing list