question about imports in a class

J dreadpiratejeff at gmail.com
Mon Dec 7 17:18:49 EST 2009


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()

Sorry for the incredibly entry-level questions...  I'm a more senior
member on a few Linux related lists/groups, and I can certainly
understand if questions as basic as these are annoying, so I'm really
trying to not ask them unless I'm just really confused about
something.

OTOH, if there's something more akin to a python newbies kind of list
where this kind of basic thing is more appropriate, please let me
know, because really, I don't want to clutter up python-list with
stuff that would be better off elsewhere.


-- 

Marie von Ebner-Eschenbach  - "Even a stopped clock is right twice a
day." - http://www.brainyquote.com/quotes/authors/m/marie_von_ebnereschenbac.html



More information about the Python-list mailing list