Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52532

Re: .split() Qeustion

From Terry Reedy <tjreedy@udel.edu>
Subject Re: .split() Qeustion
Date 2013-08-14 15:45 -0400
References (3 earlier) <CAN1F8qVsX4BpPvE4JuVoY7hzKB6fiBgPBCZczm7LQT7N1M+01w@mail.gmail.com> <kufqj5$b8d$1@ger.gmane.org> <mailman.571.1376481372.1251.python-list@python.org> <c9727dd8-e5c6-4569-a8cf-31c7deb0ed64@googlegroups.com> <1376499950.3355.9802231.6A03F40D@webmail.messagingengine.com>
Newsgroups comp.lang.python
Message-ID <mailman.587.1376509523.1251.python-list@python.org> (permalink)

Show all headers | View raw


On 8/14/2013 1:05 PM, random832@fastmail.us wrote:
> On Wed, Aug 14, 2013, at 10:32, wxjmfauth@gmail.com wrote:
>> I'm always and still be suprised by the number of hard coded
>> '\n' one can find in Python code when the portable (here
>> win)
>>
>>>>> os.linesep
>> '\r\n'
>>
>> exists.

> Because high-level code isn't supposed to use the os module directly.

This is a bit extreme, but definitely true for os.linesep and *much* of 
os other than os.path and maybe os.environ.

> Text-mode streams automatically convert newlines you write to them.

By default, <any possible linesep> to \n when reading files;, \n to 
os.linesep when writing. Windows is the only major OS for which 
os.linesep is not \n.

The full details, from the builtin 'open' entry:
"
newline controls how universal newlines mode works (it only applies to 
text mode). It can be None, '', '\n', '\r', and '\r\n'. It works as follows:

     When reading input from the stream, if newline is None, universal 
newlines mode is enabled. Lines in the input can end in '\n', '\r', or 
'\r\n', and these are translated into '\n' before being returned to the 
caller. If it is '', universal newlines mode is enabled, but line 
endings are returned to the caller untranslated. If it has any of the 
other legal values, input lines are only terminated by the given string, 
and the line ending is returned to the caller untranslated.

     When writing output to the stream, if newline is None, any '\n' 
characters written are translated to the system default line separator, 
os.linesep. If newline is '' or '\n', no translation takes place. If 
newline is any of the other legal values, any '\n' characters written 
are translated to the given string.
"

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

.split() Qeustion eschneider92@comcast.net - 2013-08-13 21:51 -0700
  Re: .split() Qeustion Gary Herron <gary.herron@islandtraining.com> - 2013-08-13 22:12 -0700
    Re: .split() Qeustion Alister <alister.ware@ntlworld.com> - 2013-08-14 08:30 +0000
      Re: .split() Qeustion Joshua Landau <joshua@landau.ws> - 2013-08-14 11:31 +0100
        Re: .split() Qeustion Alister <alister.ware@ntlworld.com> - 2013-08-14 13:29 +0000
        Re: .split() Qeustion Duncan Booth <duncan.booth@invalid.invalid> - 2013-08-15 09:15 +0000
          Re: .split() Qeustion wxjmfauth@gmail.com - 2013-08-15 02:46 -0700
            Re: .split() Qeustion Chris Angelico <rosuav@gmail.com> - 2013-08-15 10:54 +0100
            Re: .split() Qeustion Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-15 11:22 +0000
              Re: .split() Qeustion wxjmfauth@gmail.com - 2013-08-15 06:58 -0700
      Re: .split() Qeustion Peter Otten <__peter__@web.de> - 2013-08-14 13:45 +0200
      Re: .split() Qeustion Joshua Landau <joshua@landau.ws> - 2013-08-14 12:55 +0100
        Re: .split() Qeustion wxjmfauth@gmail.com - 2013-08-14 07:32 -0700
          Re: .split() Qeustion random832@fastmail.us - 2013-08-14 13:05 -0400
            Re: .split() Qeustion Steven D'Aprano <steve@pearwood.info> - 2013-08-15 07:17 +0000
          Re: .split() Qeustion Chris Angelico <rosuav@gmail.com> - 2013-08-14 18:14 +0100
            Re: .split() Qeustion wxjmfauth@gmail.com - 2013-08-15 00:46 -0700
              Re: .split() Qeustion Lele Gaifax <lele@metapensiero.it> - 2013-08-15 16:38 +0200
              Re: .split() Qeustion MRAB <python@mrabarnett.plus.com> - 2013-08-15 15:54 +0100
              Re: .split() Qeustion Lele Gaifax <lele@metapensiero.it> - 2013-08-15 17:30 +0200
              Re: .split() Qeustion Chris Angelico <rosuav@gmail.com> - 2013-08-15 16:43 +0100
                Re: .split() Qeustion Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-16 04:13 +0000
                Re: .split() Qeustion Roy Smith <roy@panix.com> - 2013-08-16 00:29 -0400
                Re: .split() Qeustion Dave Angel <davea@davea.name> - 2013-08-16 05:27 +0000
                Re: .split() Qeustion Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-17 02:38 +0000
                Re: .split() Qeustion Chris Angelico <rosuav@gmail.com> - 2013-08-17 03:45 +0100
                Re: .split() Qeustion Gene Heskett <gheskett@wdtv.com> - 2013-08-16 10:30 -0400
                Re: .split() Qeustion Gene Heskett <gheskett@wdtv.com> - 2013-08-16 10:24 -0400
                Re: .split() Qeustion Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-08-17 11:16 +1200
                Re: .split() Qeustion Ben Finney <ben+python@benfinney.id.au> - 2013-08-16 15:59 +1000
                Re: .split() Qeustion Roy Smith <roy@panix.com> - 2013-08-16 07:14 -0400
                Re: .split() Qeustion wxjmfauth@gmail.com - 2013-08-16 06:14 -0700
                Re: .split() Qeustion Roy Smith <roy@panix.com> - 2013-08-16 09:23 -0400
                Re: .split() Qeustion wxjmfauth@gmail.com - 2013-08-17 01:09 -0700
                Re: .split() Qeustion Roy Smith <roy@panix.com> - 2013-08-17 07:55 -0400
                Re: .split() Qeustion Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-08-18 11:30 +1200
                Re: .split() Qeustion wxjmfauth@gmail.com - 2013-08-18 00:17 -0700
                Re: .split() Qeustion Grant Edwards <invalid@invalid.invalid> - 2013-08-16 13:59 +0000
              Re: .split() Qeustion Joshua Landau <joshua@landau.ws> - 2013-08-15 17:54 +0100
              Re: .split() Qeustion Chris Angelico <rosuav@gmail.com> - 2013-08-15 19:28 +0100
                Re: .split() Qeustion Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-16 04:17 +0000
              Re: .split() Qeustion Joshua Landau <joshua@landau.ws> - 2013-08-15 19:40 +0100
              Re: .split() Qeustion Terry Reedy <tjreedy@udel.edu> - 2013-08-15 17:40 -0400
                Re: .split() Qeustion Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-16 04:22 +0000
              Re: .split() Qeustion Dave Angel <davea@davea.name> - 2013-08-15 22:56 +0000
                Re: .split() Qeustion Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-16 04:39 +0000
                Re: .split() Qeustion Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-16 04:41 +0000
          Re: .split() Qeustion Tim Chase <python.list@tim.thechases.com> - 2013-08-14 12:29 -0500
          Re: .split() Qeustion Skip Montanaro <skip@pobox.com> - 2013-08-14 12:38 -0500
          Re: .split() Qeustion Chris Angelico <rosuav@gmail.com> - 2013-08-14 18:46 +0100
          Re: .split() Qeustion Terry Reedy <tjreedy@udel.edu> - 2013-08-14 15:45 -0400
  Re: .split() Qeustion Dave Angel <davea@davea.name> - 2013-08-14 05:35 +0000
  Re: .split() Qeustion eschneider92@comcast.net - 2013-08-13 22:44 -0700
  Re: .split() Qeustion Krishnan Shankar <i.am.songoku@gmail.com> - 2013-08-13 22:37 -0700
  .split() Qeustion "Alfonso Andalon Jr." <alfonsoandalon@gmail.com> - 2013-08-16 21:31 -0700

csiph-web