0
je devrais garder un décalage dans le fichier et lire cette ligne offset et émettre, mise à jour offset = décalage + 1besoin chaîne ou tampon, fichier trouvé
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
mais je me suis erreur
with open(self.f) as f:
TypeError: coercing to Unicode: need string or buffer, file found
merci pour la réponse, mais excusez-moi je suis nouveau à python. vous voulez dire écrire comme ça avec open (self.f): self.f.readlines() [self._offset]? – user3188912
êtes-vous toujours là? – user3188912