0
在這個問題上我需要你的幫助。我讀到,噴口負責讀取數據或準備在Bolt中進行處理。所以我寫了一些代碼在噴口中打開文件並逐行讀取噴口邏輯錯誤
class SimSpout(storm.Spout):
# Not much to do here for such a basic spout
def initialize(self, conf, context):
## Open the file with read only permit
self.f = open('data.txt', 'r')
## Read the first line
self._conf = conf
self._context = context
storm.logInfo("Spout instance starting...")
# Process the next tuple
def nextTuple(self):
# check if it reach at the EOF to close it
for line in self.f.readlines():
# Emit a random sentence
storm.logInfo("Emiting %s" % line)
storm.emit([line])
# Start the spout when it's invoked
SimSpout().run()
是嗎?
許多感謝回答,我得到這個「打開(self.f)作爲f: TypeError:強制爲Unicode:需要字符串或緩衝區,發現文件「 – user3188912
我解決了這個錯誤,因爲我打開了兩次文件,但我得到另一個AttributeError:'SimSpout'對象沒有屬性'_offset'我尋找解決它,但沒有找到任何幫助 – user3188912