Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'charset:iso-8859-7': 0.04; 'syntax': 0.04; 'encoding': 0.05; 'interpreter.': 0.07; 'utf-8': 0.07; 'string': 0.09; 'ascii': 0.09; 'executable': 0.09; 'f.close()': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:/ 10': 0.09; 'skip:\\ 40': 0.09; 'python': 0.11; '"w")': 0.16; 'ascii,': 0.16; 'filename,': 0.16; 'interpreter,': 0.16; 'non-ascii': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'rules.': 0.16; 'script,': 0.16; 'silly': 0.16; 'subject:issue': 0.16; 'uses,': 0.16; 'with?': 0.16; 'wrote:': 0.18; 'machine': 0.22; 'header:User- Agent:1': 0.23; 'byte': 0.24; 'bytes': 0.24; 'certainly': 0.24; 'interpret': 0.24; 'decide': 0.24; 'file.': 0.24; 'looks': 0.24; 'header:X-Complaints-To:1': 0.27; "doesn't": 0.30; 'characters': 0.30; "i'm": 0.30; 'lines': 0.31; '>>>>': 0.31; 'file': 0.32; 'this.': 0.32; 'text': 0.33; 'says': 0.33; 'entirely': 0.33; 'skip:# 10': 0.33; 'case,': 0.35; 'hundreds': 0.35; 'one,': 0.35; 'but': 0.35; 'add': 0.35; 'there': 0.35; 'to:addr:python-list': 0.38; 'issue': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'dave': 0.60; 'first': 0.61; 'save': 0.62; 'name': 0.63; 'different': 0.65; 'skip:f 50': 0.65; 'within': 0.65; 'default': 0.69; 'wish': 0.70; 'angel': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: UnicodeDecodeError issue Date: Wed, 4 Sep 2013 12:38:04 +0000 (UTC) References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <3e549761-4323-4379-b4e4-ce51597d59c0@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-7 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 174.32.174.36 User-Agent: XPN/1.2.6 (Street Spirit ; Linux) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 66 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1378298304 news.xs4all.nl 15925 [2001:888:2000:d::a6]:45113 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53624 On 4/9/2013 07:38, Ferrous Cranus wrote: > Στις 4/9/2013 2:26 μμ, ο/η Dave Angel έγραψε: >> >>>> >>>> So first in the interpreter, I ran >>>> >>>> >>>> >>>>>>>> f = open("junk.txt", "w") >>>> >>>>>>>> f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') >>>> >>>>>>>> f.close() >>>> >>>> >>>> >> So since the tets.py file was a sidetrack, I just ran those three lines >> in the interpreter. >> > I'm still consused about this. > > say we save those 3 lines inside junk.txt and we save it by default as utf-8 > > when we 'file junk.txt' > > what will file respond with? junk2.txt: ASCII text > > filename's charset? > > or > > will it llook at the bystering within to decide what encoding it uses? > 'file' isn't magic. And again, it doesn't look at the filename, it looks at the content. What heuristics it uses, I don't know, but it has hundreds of them. ( I wish you hadn't confused the issue by using the same name junk.txt for an entirely different purpose) When it looks at a file like this one, it looks only at the bytes within it. In this case, the instance of 'file' on my machine decides it's an ASCII file. if I add an silly shebang line #!/usr/tmp/pyttthon it says junk2.txt: a /usr/tmp/pyttthon script, ASCII text executable It doesn't know it's python, it just trusts the shebang line. And it identifies it as ASCII, not utf-8, since there are no non-ascii characters in it. It certainly does not try to interpret the b'xxxx' byte string by Python syntax rules. -- DaveA