Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.021 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'explicitly': 0.04; 'binary': 0.05; 'programs.': 0.11; "(i'm": 0.16; 'decode': 0.16; 'exceptions.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.17; 'thu,': 0.17; 'received:209.85.214.174': 0.21; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'lines': 0.28; 'division': 0.29; 'mode.': 0.29; 'though.': 0.29; 'file': 0.32; 'problem': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'text': 0.34; 'open': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'your': 0.60; "you'll": 0.62; 'back': 0.62; '26,': 0.65; 'jul': 0.65 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=epa/rg86kTg0PEtq0OLBUbtDyiqgYzagy/ECf2dLuxY=; b=oZ+b9S+kg6Ke4j2sjj/Y5BtA3y2F4aOJUBVIP7Ygbqh6e1QVk5HDYR5HZ58HrgyPr0 z7T0UeY4vBD/5nSB+sdzT91cDsQ1uGDkT73JhyfomrX5sW6cNeDLUgWWjn3YPVXkDReJ HcUGSz52pyyerswvQtR4mwmlA4/Ep7HNy0rqzadUFIYZawiY3ApBS0kHYIt1xOy3ntxu yZ5EJ8taR+OMheTND42/OxXEzUEknh2Vo864yDucmD6Xj2qwToM6rmUURjdxUVKuiOzv sn0QPJcGJ88NVaAqL35G28XvmsOQ4RKPb8AwsVXDhnREIKdX2PI36PCmafZ2omLXRqwm XYwQ== MIME-Version: 1.0 In-Reply-To: <38f5cdaf-c021-4ccd-8fcb-c68b21d3aeb2@w24g2000vby.googlegroups.com> References: <04f7ff8d-9881-4a04-ab2e-b5573b5f3cd1@googlegroups.com> <38f5cdaf-c021-4ccd-8fcb-c68b21d3aeb2@w24g2000vby.googlegroups.com> Date: Thu, 26 Jul 2012 19:46:14 +1000 Subject: Re: catch UnicodeDecodeError From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 13 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343295977 news.xs4all.nl 6943 [2001:888:2000:d::a6]:51537 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26076 On Thu, Jul 26, 2012 at 5:46 PM, Jaroslav Dobrek wrote: > My problem is solved. What I need to do is explicitly decode text when > reading it. Then I can catch exceptions. I might do this in future > programs. Apologies if it's already been said (I'm only skimming this thread), but ISTM that you want to open the file in binary mode. You'll then get back a bytes() instead of a str(), and you can attempt to decode it separately. You may then need to do your own division into lines that way, though. ChrisA