[Tutor] Handling Objects
Eric Walker
ewalker at micron.com
Wed Oct 5 23:41:59 CEST 2005
New to Python and trying to do some class stuff with a simple task.
Problem:
1) get a list of file names in a directory
2) create variables with the same name of each filename pulled from the
directory.
3) Create an object for each and pass into the __init__ method the stringname
of the file name.
This way I get a collection of objects that are the same name as the file name
and within each instance of the class , a particular attribute will have the
string name of the object. Hope this isn't too confusing.. example.
class TPROJ:
def __init__(self,value):#createMethod auto executes since it has __
self.BASENAME = value
def display(self):#display method
print self.BASENAME
def getNames():
import os
currentDir=os.getcwd()
temp=currentDir + '/TEMP'
os.chdir(temp)
baseList=os.listdir(".")
for name in baseList:
name = TPROJ(name)
print name
Can anyone see what I am trying to do?
Python Newbie.......
More information about the Tutor
mailing list