![](/img/trans.png)
[英]In django, can you load a django app into the python interpreter like in rails?
[英]Can you create an object which acts like None when typed into the interpreter in Python?
是否可以創建具有以下行為的類?
>>> x = X()
>>> x
>>>
我嘗試了以下
class X:
def __repr__(self):
return ""
導致
>>> x = X()
>>> x
>>>
以及以下內容:
class X:
def __repr__(self):
return repr(None)
>>> x = X()
>>> x
None
>>>
以及其他想法,例如在調用repr
時從__repr__
錯誤返回None
,並從NoneType
派生錯誤。
您不能根據自己的喜好創建一個值,但是可以更改交互式提示顯示值的方式。 有關如何自定義顯示的信息,請參見sys.displayhook 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.