Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'encoding': 0.05; 'output': 0.05; 'attribute': 0.07; 'correct.': 0.07; 'skip:u 30': 0.07; 'string': 0.09; "'a'": 0.09; 'bits': 0.09; 'bytes,': 0.09; 'received:151': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; '*you*': 0.16; 'char,': 0.16; 'emanuele': 0.16; 'garbage': 0.16; 'opposite': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'unicode,': 0.16; 'sat,': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'memory': 0.22; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'char': 0.24; 'errors.': 0.24; 'unicode': 0.24; 'header:X -Complaints-To:1': 0.27; 'array': 0.29; '"",': 0.31; '-0700,': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'writes:': 0.31; 'file': 0.32; '(most': 0.33; 'subject:from': 0.34; 'subject: (': 0.35; 'problem.': 0.35; 'one,': 0.35; 'there': 0.35; 'doing': 0.36; 'wrong': 0.37; 'mapping': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'che': 0.60; 'course.': 0.60; 'back': 0.62; 'times': 0.62; 'happen': 0.63; 'skip:n 10': 0.64; 'actually,': 0.84; 'characters,': 0.84; 'drive.': 0.84; 'flipping': 0.84; 'no:': 0.84; 'quando': 0.84; 'respectively': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Lele Gaifax Subject: Re: Changing filenames from Greeklish => Greek (subprocess complain) Date: Sun, 09 Jun 2013 10:55:43 +0200 Organization: Nautilus Entertainments References: <7d8da6c9-fb92-4329-b207-4280f29ba664@googlegroups.com> <20130608024931.GA77888@cskk.homeip.net> <51B37173.9060601@gmail.com> <3fbb5d0e-51fb-4aed-b829-8388304a9885@googlegroups.com> <51b4249d$0$30001$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 151.62.123.243 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) Cancel-Lock: sha1:y7fDRBdjHGJ1pi9EAEoxXpIRejI= 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: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1370768144 news.xs4all.nl 15962 [2001:888:2000:d::a6]:60833 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:47433 Steven D'Aprano writes: > On Sat, 08 Jun 2013 22:09:57 -0700, nagia.retsina wrote: > >> chr('A') would give me the mapping of this char, the number 65 while >> ord(65) would output the char 'A' likewise. > > Correct. Python uses Unicode, where code-point 65 ("ordinal value 65") > means letter "A". Actually, that's the other way around: >>> chr(65) 'A' >>> ord('A') 65 >> What would happen if we we try to re-encode bytes on the disk? like >> trying: >> >> s = "νίκος" >> utf8_bytes = s.encode('utf-8') >> greek_bytes = utf_bytes.encode('iso-8869-7') >> >> Can we re-encode twice or as many times we want and then decode back >> respectively lke? > > Of course. Bytes have no memory of where they came from, or what they are > used for. All you are doing is flipping bits on a memory chip, or on a > hard drive. So long as *you* remember which encoding is the right one, > there is no problem. If you forget, and start using the wrong one, you > will get garbage characters, mojibake, or errors. Uhm, no: "encode" transforms a Unicode string into an array of bytes, "decode" does the opposite transformation. You cannot do the former on an "arbitrary" array of bytes: >>> s = "νίκος" >>> utf8_bytes = s.encode('utf-8') >>> greek_bytes = utf8_bytes.encode('iso-8869-7') Traceback (most recent call last): File "", line 1, in AttributeError: 'bytes' object has no attribute 'encode' ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. lele@metapensiero.it | -- Fortunato Depero, 1929.