Thanks for the tips. It's a 2000 line program, written by someone else.
I'm not fluent in Python, yet, but making good progress in implementing
new features. The various 'attr' facilities are a bit esoteric, but
look useful. The often found, by Google "x.foobar=123", example is a
pretty narrow focus on explaining, at least, setattr. Yes, consistency is important here, but it may take some rewriting of the original code. wesley chun wrote: On Mon, Feb 16, 2009 at 8:24 PM, Wayne Watson <sierra_mtnv...@sbcglobal.net> wrote:I suspect I'm in need of setattr for this in a GUI program I'm modifying.Initally, a variable. self.stop_time is created as type datetime.time, with the default value 06:00:00, a time stamp, during entry into the mainloop. self.stop_time = datetime.time(10,10,10). The user reads his configuration file with the time stamp value of 08:00:00. self.time_stop becomes type string. He then goes to a dialog to change time stop, and it tries to access self.time_stop, and find is needs to have the attribute strftime, as in: set_loc_dict[ "stop_time" ] = self.stop_time.strftime("%H:%M:%S") When reading the configuration file, how do I make sure that self.time_stop is really has the strftime attribute?close. what you need is hasattr(), which returns True/False. you can also use getattr() with a default value as well. the problem you're facing is that the object is now a str and not a datetime.time as you mentioned. you have 2 options: a. keep everything as a string and manipulate the value that way, or b. convert the string to a datetime.time object and keep it like that good luck! -wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 "Python Fundamentals", Prentice Hall, (c)2009 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com --
Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) Shhhh, quiet. I'm thinking about filling this space. Web Page: <www.speckledwithstars.net/> |
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor