Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringIO and with statement #51675

Closed
jmfauth mannequin opened this issue Dec 3, 2009 · 2 comments
Closed

StringIO and with statement #51675

jmfauth mannequin opened this issue Dec 3, 2009 · 2 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@jmfauth
Copy link
Mannequin

jmfauth mannequin commented Dec 3, 2009

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']

    @jmfauth
    Copy link
    Mannequin Author

    jmfauth mannequin commented Dec 3, 2009

    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

    >>

    @jmfauth jmfauth mannequin added the type-bug An unexpected behavior, bug, or error label Dec 3, 2009
    @briancurtin
    Copy link
    Member

    bpo-1286 looks related

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants