How to read the Python tutorial?

rantingrick rantingrick at gmail.com
Wed Nov 10 10:51:38 EST 2010


On Nov 10, 9:13 am, Zeynel <azeyn... at gmail.com> wrote:
> For instance, when the tutorial hashttp://docs.python.org/release/2.6/library/datetime.html
>
> class datetime.datetime
> A combination of a date and a time. Attributes: year, month, day,
> hour, minute, second, microsecond, and tzinfo.
>
> What does this mean? How do I use it?
>
> For instance, I have a DateTimeProperty mDate that I get from a query
> in Google App Engine. This mDate has value
>
> mDATE = 2010-11-10 14:35:22.863000

Wait a minute i am confused...? Does Python have a "text" object that
magically turns into a datetime object?

>>> mDATE = 2010-11-10 14:35:22.863000
SyntaxError: invalid syntax

hmm, apparently not! Usually in order to use methods of an object, you
must create an object first or more specifically an instance.

>>> dateobj = datetime.date(2010,11,10)
>>> dir(dateobj)
['__add__', '__class__', '__delattr__', '__doc__', '__eq__',
'__format__', '__ge__', '__getattribute__', '__gt__', '__hash__',
'__init__', '__le__', '__lt__', '__ne__', '__new__', '__radd__',
'__reduce__', '__reduce_ex__', '__repr__', '__rsub__', '__setattr__',
'__sizeof__', '__str__', '__sub__', '__subclasshook__', 'ctime',
'day', 'fromordinal', 'fromtimestamp', 'isocalendar', 'isoformat',
'isoweekday', 'max', 'min', 'month', 'replace', 'resolution',
'strftime', 'timetuple', 'today', 'toordinal', 'weekday', 'year']



More information about the Python-list mailing list