簡體   English   中英

Python twisted reactor undefined變量

[英]Python twisted reactor undefined variable

我正在學習本教程: http//www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server

但是當我寫的時候

reactor.listenTCP(80, factory)

eclipse告訴我它是一個未定義的變量..我安裝了扭曲,可以獲得導入的自動完成,但這不會工作..谷歌顯示更多有這個問題,但我找不到任何解決方案..謝謝!

編輯:完整的代碼:

from twisted.internet.protocol import Factory
from twisted.internet import reactor

factory = Factory()
reactor.listenTCP(80, factory)
reactor.run()

這是與Eclipse / PyDev執行靜態分析的方式相關的已知問題。

如果仔細觀察, reactor對象在導入時並不存在於twisted.internet模塊中。 該模塊是空的。

當Eclipse / PyDev嘗試編譯字節碼時,靜態分析不會在twisted.internet模塊中看到reactor對象並將其標記為未定義的變量,即使它實際上存在於運行時(通過一些Twisted魔法注冊我不能說明)。

我使用的解決方法很簡單,只需添加#@ UndefinedVariable來抑制錯誤:

reactor.run() #@UndefinedVariable

瞧。 沒有IDE錯誤。

嘗試在eclipse之外運行它。 如果它有效,這是一個日食問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM