py3k: datetime resolution / isoformat

Chris Rebert clp2 at rebertia.com
Fri Feb 25 23:37:56 EST 2011


On Fri, Feb 25, 2011 at 6:21 PM,  <spam at uce.gov> wrote:
>
> When I do:
>
>    datetime.datetime.now().isoformat(' ')
>
> I get the time with the microseconds. The docs says:
> "if microsecond is 0 YYYY-MM-DDTHH:MM:SS+HH:MM".
>
> How do I set microsecond to 0?
>
>     >>> datetime.datetime.microsecond = 0
>    Traceback (most recent call last):
>      File "<stdin>", line 1, in <module>
>    TypeError: can't set attributes of built-in/extension type
> 'datetime.datetime'

Here you're trying to modify the *class* itself, not an *instance* of
the class like you want to.
However, datetime.datetime instances are immutable anyway. You have to
create a new instance with the desired values, as Ned Deily
demonstrated.

Cheers,
Chris
--
Your "From:" address is annoying.
http://blog.rebertia.com



More information about the Python-list mailing list