Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'ascii': 0.07; 'fine,': 0.07; 'pep': 0.07; 'argument,': 0.09; 'fetch': 0.09; 'newline': 0.09; 'url:dev': 0.09; 'url:peps': 0.09; 'def': 0.13; 'guys,': 0.16; 'newlines': 0.16; 'tuple):': 0.16; 'url:sk': 0.16; 'case.': 0.16; 'figure': 0.18; 'file,': 0.22; 'detect': 0.25; 'testing': 0.28; 'thanks.': 0.28; 'daniel': 0.29; 'idea?': 0.31; 'however,': 0.31; "can't": 0.31; 'anyone': 0.31; 'to:addr :python-list': 0.32; 'using': 0.34; 'file': 0.35; 'characters': 0.35; 'correctly': 0.35; 'header:User-Agent:1': 0.35; 'none': 0.36; 'case': 0.37; 'url:python': 0.37; 'code:': 0.38; 'url:org': 0.38; 'used': 0.38; 'end': 0.39; 'to:addr:python.org': 0.39; 'works': 0.40; 'would': 0.40; 'header:Received:5': 0.40; 'best': 0.60; 'charset:windows-1252': 0.61; 'received:188': 0.75; 'argument;': 0.84; 'from:charset:windows-1252': 0.84; 'received:188.40': 0.84 X-Virus-Scanned: amavisd-new at rulez.sk Date: Sat, 23 Apr 2011 20:09:27 +0200 From: =?windows-1252?Q?Daniel_Ger=9Eo?= User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.17pre) Gecko/20110414 Lanikai/3.1.10pre MIME-Version: 1.0 To: python-list@python.org Subject: detecting newline character Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1303582172 news.xs4all.nl 41102 [::ffff:82.94.164.166]:44939 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:3917 Hello guys, I need to detect the newline characters used in the file I am reading. For this purpose I am using the following code: def _read_lines(self): with contextlib.closing(codecs.open(self.path, "rU")) as fobj: fobj.readlines() if isinstance(fobj.newlines, tuple): self.newline = fobj.newlines[0] else: self.newline = fobj.newlines This works fine, if I call codecs.open() without encoding argument; I am testing with an ASCII enghlish text file, and in such case the fobj.newlines is correctly detected being as '\r\n'. However, when I call codecs.open() with encoding='ascii' argument, the fobj.newlines is None and I can't figure out why that is the case. Reading the PEP at http://www.python.org/dev/peps/pep-0278/ I don't see any reason why would I end up with newlines being None after I call readlines(). Anyone has an idea? You can fetch the file I am testing with from http://danger.rulez.sk/subrip_ascii.srt Thanks. -- S pozdravom / Best regards Daniel Gerzo