[Tutor] Changing the Attribute of a Variable

Kent Johnson kent37 at tds.net
Tue Feb 17 20:11:19 CET 2009


On Tue, Feb 17, 2009 at 7:44 AM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:

> ==============OpenConfigFile==========
>   def OpenConfigFile(self):
>       def time_tuple(tstring):
>           t = tstring.split(':')
>           print 'here is t', t
>           tnum = ()
>           for j in range(0,len(t)):
>               tnum = tnum+(string.atoi(t[j]),)             return tnum
>
>       print "OCFile entered"
>       print
>       config_file_name = askopenfilename( title="Open Configuration File",
>                                   filetypes=CEN_FILE_TYPES )
>       config_file=open(config_file_name,'r')
>       first_line = config_file.readline()   # skip first line
>       for (j,newline) in enumerate(config_file):
>           aline = newline[:-1]
>           aline.rstrip()
>           (config_var, config_value) = aline.split('=')
>           config_type = self.config_var_list[j][1][1]
>           self_var = "self." + config_var
>           print "ocf: ",config_var,config_value,"self_var=",self_var
>           if config_var == DAT: # Date type, expecting hh:mm:ss

What is DAT? Where is it defined? Why should the config variable name
(config_var) be equal to DAT? Is this code block being executed at
all?

Kent

>               t_ntup = time_tuple(config_value)
>               stime = datetime.time(t_ntup[0],t_ntup[1],t_ntup[2])
>               print "type stime: ",type(stime)
>               # Date vars should be type datetime.time
>               config_value = str(stime)
>           else:
>               self_var_assignment = self_var +'='+ config_value
>           print "self_var_assignment", self_var_assignment
>           abc = self
>           # self_var_assignment
>           setattr(self, config_var, config_value)
>       config_file.close()


More information about the Tutor mailing list