Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4a.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; 'from:addr:yahoo.co.uk': 0.04; 'explicitly': 0.05; 'subject:text': 0.05; 'correct.': 0.07; 'string': 0.09; 'bytes,': 0.09; 'bytes.': 0.09; 'dan': 0.09; 'filenames': 0.09; 'hierarchical': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'strings.': 0.09; 'violates': 0.09; 'subject:question': 0.10; 'python': 0.11; 'language.': 0.14; 'displaying': 0.16; 'example).': 0.16; 'fine.': 0.16; 'of)': 0.16; 'os.curdir': 0.16; 'os:': 0.16; 'pathnames': 0.16; 'personally,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'language': 0.16; 'wrote:': 0.18; 'module': 0.19; 'seems': 0.21; '>>>': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'directory.': 0.24; 'documented': 0.24; 'instead.': 0.24; 'regardless': 0.24; "i've": 0.25; 'developers': 0.25; 'mention': 0.26; 'header:X-Complaints- To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; "doesn't": 0.30; "i'm": 0.30; '>>>>': 0.31; 'file': 0.32; 'probably': 0.32; 'agreed': 0.32; "we're": 0.32; 'linux': 0.33; 'url:python': 0.33; 'something': 0.35; 'anybody': 0.35; 'objects': 0.35; 'but': 0.35; 'consistent': 0.36; 'representing': 0.36; 'url:org': 0.36; 'should': 0.36; 'being': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'recent': 0.39; 'itself': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'removing': 0.60; 'skip:t 30': 0.61; 'url:3': 0.61; 'simply': 0.61; 'simple': 0.61; 'refer': 0.63; 'our': 0.64; 'more': 0.64; 'charset:windows-1252': 0.65; 'effectively': 0.66; 'here': 0.66; 'mar': 0.68; '2014,': 0.84; '2015': 0.84; 'same,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Newbie question about text encoding Date: Sat, 07 Mar 2015 19:00:47 +0000 References: <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> <87bnk4yci1.fsf@elektro.pacujo.net> <877fusybkb.fsf@elektro.pacujo.net> <87y4n8wvc3.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-147-191-2.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 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: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1425754874 news.xs4all.nl 2905 [2001:888:2000:d::a6]:54992 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:87123 On 07/03/2015 18:34, Dan Sommers wrote: > On Sun, 08 Mar 2015 05:13:09 +1100, Chris Angelico wrote: > >> On Sun, Mar 8, 2015 at 5:02 AM, Dan Sommers wrote: >>> On Sun, 08 Mar 2015 04:59:56 +1100, Chris Angelico wrote: >>> >>>> On Sun, Mar 8, 2015 at 4:50 AM, Marko Rauhamaa wrote: >>> >>>>> Correct. Linux pathnames are octet strings regardless of the locale. >>>>> >>>>> That's why Linux developers should refer to filenames using bytes. >>>>> Unfortunately, Python itself violates that principle by having >>>>> os.listdir() return str objects (to mention one example). >>>> >>>> Only because you gave it a str with the path name. If you want to >>>> refer to file names using bytes, then be consistent and refer to ALL >>>> file names using bytes. As I demonstrated, that works just fine. >>> >>> Python 3.4.2 (default, Oct 8 2014, 10:45:20) >>> [GCC 4.9.1] on linux >>> Type "help", "copyright", "credits" or "license" for more information. >>>>>> import os >>>>>> type(os.listdir(os.curdir)[0]) >>> >> >> Help on module os: >> >> DESCRIPTION >> This exports: >> - os.curdir is a string representing the current directory ('.' or ':') >> - os.pardir is a string representing the parent directory ('..' or '::') >> >> Explicitly documented as strings. If you want to work with strings, >> work with strings. If you want to work with bytes, don't use >> os.curdir, use bytes instead. Personally, I'm happy using strings, but >> if you want to go down the path of using bytes, you simply have to be >> consistent, and that probably means being platform-dependent anyway, >> so just use b"." for the current directory. > > I think we're all agreeing: not all file systems are the same, and > Python doesn't smooth out all of the bumps, even for something that > seems as simple as displaying the names of files in a directory. And > that's *after* we've agreed that filesystems contain files in > hierarchical directories. > > Dan > Isn't pathlib https://docs.python.org/3/library/pathlib.html#module-pathlib effectively a more recent attempt at smoothing or even removing (some of) the bumps? Has anybody here got experience of it as I've never used it? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence