0
我应该保持一个偏移量文件并读取该偏移线,放出,更新偏移=偏移+ 1需要字符串或缓冲区,文件中发现
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
self._offset = 0
storm.logInfo("Spout instance starting...")
# Process the next tuple
def nextTuple(self):
# check if it reach at the EOF to close it
with open(self.f) as f:
f.readlines()[self._offset]
#Emit a random sentence
storm.logInfo("Emiting %s" % line)
storm.emit([line])
self._offset = self._offset + 1
,但我得到的错误
with open(self.f) as f:
TypeError: coercing to Unicode: need string or buffer, file found
感谢回答,但对不起,我是新来的蟒蛇。你的意思是用open打开(self.f): self.f.readlines()[self._offset]? – user3188912
你还在吗? – user3188912