我正在使用扭曲的API並正在通過這個例子。 我插入了一個打印語句打印「在getdummydata」正確的縮進。代碼如下:縮進錯誤python
from twisted.internet import reactor, defer
def getDummyData(x):
"""
This function is a dummy which simulates a delayed result and
returns a Deferred which will fire with that result. Don't try too
hard to understand this.
"""
print "in getdummydata"
d = defer.Deferred()
# simulate a delayed result by asking the reactor to fire the
# Deferred in 2 seconds time with the result x * 3
reactor.callLater(2, d.callback, x * 3)
return d
def printData(d):
"""
Data handling function to be added as a callback: handles the
data by printing the result
"""
print d
d = getDummyData(3)
d.addCallback(printData)
# manually set up the end of the process by asking the reactor to
# stop itself in 4 seconds time
reactor.callLater(4, reactor.stop)
# start up the Twisted reactor (event loop handler) manually
reactor.run()
但是當我運行的代碼,它給下面的壓痕錯誤:
File "C:\Python26\programs\twisttest.py", line 9
print "in getdummydata"
^
IndentationError: unexpected indent
請任何人都可以解釋,爲什麼?
工作對我來說很好,正如預期的那樣。確保你到處都有4個空格,並且沒有標籤。 – delnan 2010-08-25 19:30:04