python - need string or buffer, file found -
i should keep offset file , read offset line , emit, update offset = offset + 1
class simspout(storm.spout): # not here such basic spout def initialize(self, conf, context): ## open file read permit self.f = open('data.txt', 'r') ## read first line self._conf = conf self._context = context self._offset = 0 storm.loginfo("spout instance starting...") # process next tuple def nexttuple(self): # check if reach @ eof close open(self.f) f: f.readlines()[self._offset] #emit random sentence storm.loginfo("emiting %s" % line) storm.emit([line]) self._offset = self._offset + 1
but got error
with open(self.f) f: typeerror: coercing unicode: need string or buffer, file found
you opening file in line
self.f = open('data.txt', 'r')
and trying open file handle instead of same file in line
with open(self.f) f:
instead, in nexttuple
, use self.f
instead of f
Comments
Post a Comment