Skip to content

exec(open(filename)) doesn't work #47442

Closed

Description

@ms
mannequin
BPO 3192
Nosy @brettcannon, @leifwalsh
Superseder
  • bpo-1762972: 'exec' does not accept what 'open' returns
  • 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 2008-06-26.08:58:37.997>
    created_at = <Date 2008-06-24.20:45:45.963>
    labels = ['interpreter-core', 'type-bug']
    title = "exec(open(filename)) doesn't work"
    updated_at = <Date 2008-06-26.08:58:37.981>
    user = 'https://bugs.python.org/ms'

    bugs.python.org fields:

    activity = <Date 2008-06-26.08:58:37.981>
    actor = 'georg.brandl'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-06-26.08:58:37.997>
    closer = 'georg.brandl'
    components = ['Interpreter Core']
    creation = <Date 2008-06-24.20:45:45.963>
    creator = 'ms'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 3192
    keywords = []
    message_count = 8.0
    messages = ['68700', '68701', '68702', '68703', '68704', '68705', '68708', '68735']
    nosy_count = 3.0
    nosy_names = ['brett.cannon', 'ms', 'leif.walsh']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = '1762972'
    type = 'behavior'
    url = 'https://bugs.python.org/issue3192'
    versions = ['Python 3.0']

    Activity

    1. ms commented on Jun 24, 2008

      msmannequin
      MannequinAuthor

      In 2.5, exec(open(filename)), where filename refers to a file with
      python code, executes the code.
      In 2.5, open returns an open file, but in 3.0, open returns a stream,
      and so exec (which wants "a string, file, or code object, not
      TextIOWrapper") returns an error. exec should probably be able to handle
      a stream.

    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      type-bugAn unexpected behavior, bug, or error
      on Jun 24, 2008
    3. leifwalsh commented on Jun 24, 2008

      leifwalshmannequin
      Mannequin

      There's 'execfile' in Lib/idlelib/PyShell.py...I'm looking for others.

      There is also a class of functions 'exec*' (and a related class,
      'spawn*') in Lib/os.py that claims to do just what you want, but
      replacing the current process (or, in spawn*'s case, in a new thread).

      That said, I agree that exec should handle streams, and if you could
      give me a heads up as to where the code is for exec(), I could try my
      hand at a patch.

    4. ms commented on Jun 24, 2008

      msmannequin
      MannequinAuthor

      I'm actually quite new to Python. My current interpreter of choice is
      PostScript, followed by Matlab, but I've been discouraged from using
      either one here at EMC. (PostScript because it's obscure, Matlab because
      it's expensive!)

      Meanwhile, I'm on a wintel machine, making perusing the Python source
      tree difficult. So I'm not going to be much help in that regard.

      By the way, I was told that execfile is gone from python 3.

      --ms

    5. leifwalsh commented on Jun 24, 2008

      leifwalshmannequin
      Mannequin

      On Tue, Jun 24, 2008 at 3:05 PM, Mike Speciner <report@bugs.python.org> wrote:

      By the way, I was told that execfile is gone from python 3.

      It certainly isn't in the branch I just checked out.

    6. leifwalsh commented on Jun 24, 2008

      leifwalshmannequin
      Mannequin

      (isn't gone, that is)

    7. ms commented on Jun 24, 2008

      msmannequin
      MannequinAuthor

      Well, I think I found exec in bltinmodule.c,
      but execfile isn't in that file. [In the 3.0 tree.]

    8. leifwalsh commented on Jun 24, 2008

      leifwalshmannequin
      Mannequin

      execfile is in Lib/idlelib/PyShell.py, and is an instance function, so
      it's not really standard for regular code, and would also be hard to
      use correctly. Sorry.

    9. brettcannon commented on Jun 25, 2008

      @brettcannon
      Member

      bpo-1762972 supercedes 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

      interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions