homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Douglas.Alan
Recipients Douglas.Alan, benjamin.peterson, eric.araujo, facundobatista, georg.brandl, ncoghlan, nessus42, pitrou, r.david.murray, ralph.corderoy, rhettinger
Date 2010年07月02日.17:31:16
SpamBayes Score 5.660937e-05
Marked as misclassified No
Message-id <1278091878.84.0.416741249003.issue1152248@psf.upfronthosting.co.za>
In-reply-to
Content
Until this feature gets built into Python, you can use a Python-coded generator such as this one to accomplish the same effect:
def fileLineIter(inputFile,
 inputNewline="\n",
 outputNewline=None,
 readSize=8192):
 """Like the normal file iter but you can set what string indicates newline.
 
 The newline string can be arbitrarily long; it need not be restricted to a
 single character. You can also set the read size and control whether or not
 the newline string is left on the end of the iterated lines. Setting
 newline to '0円' is particularly good for use with an input file created with
 something like "os.popen('find -print0')".
 """
 if outputNewline is None: outputNewline = inputNewline
 partialLine = ''
 while True:
 charsJustRead = inputFile.read(readSize)
 if not charsJustRead: break
 partialLine += charsJustRead
 lines = partialLine.split(inputNewline)
 partialLine = lines.pop()
 for line in lines: yield line + outputNewline
 if partialLine: yield partialLine
History
Date User Action Args
2010年07月02日 17:31:20Douglas.Alansetrecipients: + Douglas.Alan, georg.brandl, rhettinger, facundobatista, ncoghlan, pitrou, benjamin.peterson, nessus42, eric.araujo, ralph.corderoy, r.david.murray
2010年07月02日 17:31:18Douglas.Alansetmessageid: <1278091878.84.0.416741249003.issue1152248@psf.upfronthosting.co.za>
2010年07月02日 17:31:17Douglas.Alanlinkissue1152248 messages
2010年07月02日 17:31:16Douglas.Alancreate

AltStyle によって変換されたページ (->オリジナル) /