generator to write N lines to file
Sayth Renshaw
flebber.crue at gmail.com
Sun Jun 23 23:41:57 EDT 2019
More information about the Python-list mailing list
Sun Jun 23 23:41:57 EDT 2019
- Previous message (by thread): finding a component in a list of pairs
- Next message (by thread): generator to write N lines to file
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Afternoon
Trying to create a generator to write the first N lines of text to a file.
However, I keep receiving the islice object not the text, why?
from itertools import islice
fileName = dir / "7oldsamr.txt"
dumpName = dir / "dump.txt"
def getWord(infile, lineNum):
with open(infile, 'r+') as f:
lines_gen = islice(f, lineNum)
yield lines_gen
for line in getWord(fileName, 5):
with open(dumpName, 'a') as f:
f.write(line)
Thanks,
Sayth
- Previous message (by thread): finding a component in a list of pairs
- Next message (by thread): generator to write N lines to file
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list