Skip to content

StringIO and with statement #51675

Closed
Closed

Description

@jmfauth
mannequin
BPO 7426
Nosy @avassalotti, @briancurtin
Superseder
  • bpo-1286: fileinput, StringIO, and cStringIO do not support the with protocol
  • 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 2009-12-04.19:45:14.761>
    created_at = <Date 2009-12-03.10:12:51.830>
    labels = ['type-bug']
    title = 'StringIO and with statement'
    updated_at = <Date 2009-12-04.19:45:14.760>
    user = 'https://bugs.python.org/jmfauth'

    bugs.python.org fields:

    activity = <Date 2009-12-04.19:45:14.760>
    actor = 'alexandre.vassalotti'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-12-04.19:45:14.761>
    closer = 'alexandre.vassalotti'
    components = ['None']
    creation = <Date 2009-12-03.10:12:51.830>
    creator = 'jmfauth'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 7426
    keywords = []
    message_count = 2.0
    messages = ['95924', '95970']
    nosy_count = 3.0
    nosy_names = ['alexandre.vassalotti', 'jmfauth', 'brian.curtin']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '1286'
    type = 'behavior'
    url = 'https://bugs.python.org/issue7426'
    versions = ['Python 2.6']

    Activity

    1. jmfauth commented on Dec 3, 2009

      jmfauthmannequin
      MannequinAuthor

      When toying with the "with" statement, I fell on this:

      Python 2.6.4

      >>> with open('abc.txt', 'r') as f:
              for line in f:
                  print line.rstrip()
                  
      abc
      def
      >>> 
      >>> import StringIO
      >>> fo = StringIO.StringIO('abc\ndef\n')
      >>> fo.seek(0)
      >>> with fo as f2:
              for line in f2:
                  print line.rstrip()
                  
      Traceback (most recent call last):
        File "<psi last command>", line 2, in <module>
      AttributeError: StringIO instance has no attribute '__exit__'
      >>> 
      >>> 

      Same result with cStringIO

      -----

      Python 3.1.1

      >>> fo = io.StringIO('abc\ndef\n')
      >>> fo.seek(0)
      0
      >>> with fo as f:
      	for line in f:
      	    print(line.rstrip())

      abc
      def

      >>

    2. added
      type-bug
      on Dec 3, 2009
    3. briancurtin commented on Dec 4, 2009

      @briancurtin
      Member

      bpo-1286 looks related

    4. 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

      type-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions