天天看點

Python: Python中的AttributeError錯誤

Python  debug 出現 AttributeError錯誤,但run是可以運作的;

原因分析: 出新了空指針的問題

一個英文的answer裡面提出的如下解決方法:

第一種方法:添加引用

from contextlib import closing      

在代碼處包裝代碼段:比如

with closing(socket.socket(socket.AF_INET,socket.SOCK_STREAM) )as s:      

可以在運作時忽略掉

第二種方法:

在函數定義處,聲明

#@contextmanager 
def function():