2016-02-09 33 views
0

這些不匹配的68回報......通知沒有unicode的,在IPython中使用python3:什麼方法確定IPython的回報,這是不是海峽或Unicode

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 

910也不匹配。 ipython如何得到datetime.date(2010, 1, 31) ,是我不應該擔心的ipython事情?謝謝

+2

你嘗試'再版()'? – DainDwarf

+0

不,我剛剛在另一篇文章中瞭解到,似乎repr是你想要的普通對象。我被拋棄了,因爲我習慣於'__str__',然後'__unicode__'在django – codyc4321

+0

@ codyc4321 http://stackoverflow.com/questions/35295601/object-string-representation-in-python-ipython-shell/35295678 #35295678 – bakkal

回答

2

IPython中使用repr()函數,調用方法__repr__()

In [1]: from datetime import date 

In [2]: d = date(2010, 1, 31) 

In [3]: print(repr(d)) 
datetime.date(2010, 1, 31) 
相關問題