[Tutor] Changing the Attribute of a Variable

Marc Tompkins marc.tompkins at gmail.com
Tue Feb 17 08:44:18 CET 2009


On Mon, Feb 16, 2009 at 8:24 PM, Wayne Watson
<sierra_mtnview at 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?
>

You already received an answer to your immediate question, but I wanted to
clarify: "strftime" is NOT an attribute, it's a method.  Calling the
strftime method of a time object returns a string, formatted according to
the pattern you specify - so what you're storing as "stop_time" is not a
time, but a string.

-- 
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090216/5393cbb9/attachment.htm>


More information about the Tutor mailing list