Eric Walker wrote: > On Thursday 06 October 2005 12:48 pm, Kent Johnson wrote > yes, I did remove this from the class. I really didn't need it in there. I > moved the check outside under the main running function. To check the name > before I even create the object. The way I had it before it would create an > object regardless if the name had a colon or not.
That makes sense. > > >> def nameCheck(self, value): >> >>> import re >>> tempREG = re.match('.*:.*',value) >>> return str(tempREG) != 'None' >> >>Still a syntax error here! >> > > Code is working as I thought it would. What syntax error do I have? Oops, I was still *reading* a syntax error :-) > > Man this group is great. I am going to be a > python coder yet..... Yep :-) > current code sample follows: A few more advanced notes for you below, just in case your brain hasn't exploded yet :-) Kent > > > import re > import string > import os > > class TPROJ: Tproj or TProj would be a more idiomatic name... > > def display(self):#display method > print self.basename > print self.project > print self.rev > print self.designator > print self.type > > def __init__(self,value):#createMethod auto executes since it has __ > self.basename = value > self.project = value.split(':')[0] > self.rev = value.split(':')[1] If you are sure there will be just one colon this can be written as self.project, self.rev = value.split(':') Tuple assignment rocks! If you try this with more than one colon you will get an error. > self.designator = "NOVALUE" > self.type = ('SW','TMOD','SWA','TMODA')#constant tuple > > > > def nameCheck(value): > tempREG = re.match('.*:.*',value) > return str(tempREG) != 'None' > > def getProjectNames(): > currentDir=os.getcwd() > nameTable = {} > temp=currentDir + '/TEMP' > print temp > os.chdir(temp) > baseList=os.listdir(".") > baseObjectList = [] > for name in baseList: > if nameCheck(name): > baseObjectList.append(TPROJ(name)) The above four lines could be replaced with a single list comprehension if you like: baseObjectList = [ TPROJ(name) for name in baseList if nameCheck(name) ] http://www.amk.ca/python/2.0/index.html#SECTION000600000000000000000 Kent > > Python Newbie... > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor