Skip to content

newline vs. newlines in io module #53141

Closed

Description

@jmfauth
mannequin
BPO 8895
Nosy @merwok, @bitdancer, @vadmium
Files
  • unnamed
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2010-06-04.11:49:40.879>
    created_at = <Date 2010-06-04.09:05:56.918>
    labels = ['type-bug', 'invalid', 'docs']
    title = 'newline vs. newlines in io module'
    updated_at = <Date 2015-02-24.23:32:58.877>
    user = 'https://bugs.python.org/jmfauth'

    bugs.python.org fields:

    activity = <Date 2015-02-24.23:32:58.877>
    actor = 'martin.panter'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2010-06-04.11:49:40.879>
    closer = 'r.david.murray'
    components = ['Documentation']
    creation = <Date 2010-06-04.09:05:56.918>
    creator = 'jmfauth'
    dependencies = []
    files = ['17553']
    hgrepos = []
    issue_num = 8895
    keywords = []
    message_count = 7.0
    messages = ['107017', '107026', '107028', '107051', '107054', '107083', '107085']
    nosy_count = 5.0
    nosy_names = ['eric.araujo', 'jmfauth', 'r.david.murray', 'docs@python', 'martin.panter']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue8895'
    versions = ['Python 2.7']

    Activity

    1. jmfauth commented on Jun 4, 2010

      jmfauthmannequin
      MannequinAuthor

      I was confused about the newline argument/attribute
      in the misc. classes of the io module until I realize
      there is a spelling issue between the docs and the
      real implementation. (Py 2.6.5, Py2.7b2). Py 3.x not
      tested.

      >>> sys.version
      2.7b2 (r27b2:81019, May  9 2010, 11:33:14) [MSC v.1500 32 bit (Intel)]
      >>> sio = io.StringIO(u'abc')
      >>> sio.encoding, type(sio.encoding)
      (None, <type 'NoneType'>)
      >>> sio.errors, type(sio.errors)
      (None, <type 'NoneType'>)
      >>> sio.newline, type(sio.newline)
      Traceback (most recent call last):
        File "<psi last command>", line 1, in <module>
      AttributeError: '_io.StringIO' object has no attribute 'newline'
      >>> sio.newlines, type(sio.newlines)
      (None, <type 'NoneType'>)
      >>> 
      
      
      >>> tio = io.TextIOWrapper(io.BytesIO())
      >>> tio.buffer, type(tio.buffer)
      (<_io.BytesIO object at 0x02E6E600>, <type '_io.BytesIO'>)
      >>> tio.encoding, type(tio.encoding)
      ('cp1252', <type 'str'>)
      >>> tio.errors, type(tio.errors)
      ('strict', <type 'str'>)
      >>> tio.line_buffering, type(tio.line_buffering)
      (False, <type 'bool'>)
      >>> tio.newline, type(tio.newline)
      Traceback (most recent call last):
        File "<psi last command>", line 1, in <module>
      AttributeError: '_io.TextIOWrapper' object has no attribute 'newline'
      >>> tio.newlines, type(tio.newlines)
      (None, <type 'NoneType'>)
      
      >>> sys.version
      2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)]
      >>> import io
      >>> tio = io.TextIOWrapper(io.BytesIO())
      >>> tio.encoding, type(tio.encoding)
      ('cp1252', <type 'str'>)
      >>> tio.line_buffering, type(tio.line_buffering)
      (False, <type 'bool'>)
      >>> tio.errors, type(tio.errors)
      (u'strict', <type 'unicode'>)
      >>> tio.newline, type(tio.newline)
      Traceback (most recent call last):
        File "<psi last command>", line 1, in <module>
      AttributeError: 'TextIOWrapper' object has no attribute 'newline'
      >>> tio.newlines, type(tio.newlines)
      (None, <type 'NoneType'>)
      >>> [e for e in dir(tio) if 'new' in e]
      ['__new__', 'newlines']
      >>>
    2. merwok commented on Jun 4, 2010

      @merwok
      Member

      Thanks for the report. Could you check the docs for 3.1 and 3.x trunk (py3k) too?

    3. added
      docsDocumentation in the Doc dir
      and removed on Jun 4, 2010
    4. changed the title [-]newline arg/attribute in the module io[/-] [+]newline vs. newlines in io module[/+] on Jun 4, 2010
    5. bitdancer commented on Jun 4, 2010

      @bitdancer
      Member

      This is as documented:

      http://docs.python.org/dev/3.0/library/io.html#io.TextIOBase.newlines

      The keyword argument is named 'newline', the attribute is named 'newlines'. The attribute does not record what was passed to the newline argument, rather it records what newlines have been actually encountered.

    6. jmfauth commented on Jun 4, 2010

      jmfauthmannequin
      MannequinAuthor

      2010/6/4 R. David Murray <report@bugs.python.org>

      R. David Murray <rdmurray@bitdance.com> added the comment:

      This is as documented:

      http://docs.python.org/dev/3.0/library/io.html#io.TextIOBase.newlines

      The keyword argument is named 'newline', the attribute is named 'newlines'.
      The attribute does not record what was passed to the newline argument,
      rather it records what newlines have been actually encountered.

      Ok, I see. I read, reread the doc prior posting, and, in my mind, it is not
      obvious to understand this subtle difference from the doc.
      Sorry for the noise.
      Regards.

    7. merwok commented on Jun 4, 2010

      @merwok
      Member

      Could you think of a way to improve the docs on that point?

    8. jmfauth commented on Jun 4, 2010

      jmfauthmannequin
      MannequinAuthor

      2010/6/4 Éric Araujo <report@bugs.python.org>

      Éric Araujo <merwok@netwok.org> added the comment:

      Could you think of a way to improve the docs on that point?

      ----------

      Quick and dirty answer.

      I have ~10 years experience with Python and it seems
      to me the io module is technically excellent.

      However, I have found it is not so obvious to
      understand the usage of all these arguments,
      errors, encoding, line_buffering, ... in the
      class constructors and methods like io.open().

      The doc describes what these arguments are,
      their states, but not too much how to use
      them.

      As an exemple, I read some time ago on the c.l.p
      mailing list, somebody complaining about the "encoding"
      argument of the class TextIOWrapper. He defined an
      "encoding='utf-8'" in the ctor and did not
      understand why his "text" was not automagically
      encoded. Answer: the encoding arg is only a kind
      of information and does not do anything.

      BTW, it was only when I read that post, I understand
      a little bit more.

      Regards.

    9. bitdancer commented on Jun 4, 2010

      @bitdancer
      Member

      This is off topic for this issue, but what you just reported makes no sense to me. TextIOWrapper calls the encoder corresponding to the specified encoding in its write method.

      That said, it is true that the IO docs are currently a class reference and not a user reference, and this should be fixed. There may even already be an open issue for this.

    10. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      docsDocumentation in the Doc dirtype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions