【发布时间】:2016-02-09 15:20:54
【问题描述】:
这些不匹配,6 和 8 的返回...注意没有 unicode,在 ipython 中使用 python3:
In [2]: from datetime import date
In [3]: d = date(2010, 1, 31)
In [6]: d
Out[6]: datetime.date(2010, 1, 31)
In [7]: d.__
d.__add__ d.__eq__ d.__hash__ d.__new__ d.__rsub__ d.__subclasshook__
d.__class__ d.__format__ d.__init__ d.__radd__ d.__setattr__
d.__delattr__ d.__ge__ d.__le__ d.__reduce__ d.__sizeof__
d.__dir__ d.__getattribute__ d.__lt__ d.__reduce_ex__ d.__str__
d.__doc__ d.__gt__ d.__ne__ d.__repr__ d.__sub__
In [7]: d.__str__
Out[7]: <method-wrapper '__str__' of datetime.date object at 0x7fb4d5733f30>
In [8]: d.__str__()
Out[8]: '2010-01-31'
In [9]: type(d)
Out[9]: datetime.date
In [10]: d.__class__
Out[10]: datetime.date
9 和 10 也不匹配。 ipython 如何获得datetime.date(2010, 1, 31)
,这是我不应该担心的 ipython 事情吗?谢谢
【问题讨论】:
-
你试过
repr()吗? -
不,我刚刚在另一篇文章中了解到,repr 似乎是您想要的普通对象。我被甩掉了,因为我习惯了
__str__,然后是 django 中的__unicode__ -
@codyc4321 stackoverflow.com/questions/35295601/…
标签: python python-3.x unicode ipython python-3.4