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

execfile() removed from Python3 #49774

Closed
vstinner opened this issue Mar 20, 2009 · 6 comments
Closed

execfile() removed from Python3 #49774

vstinner opened this issue Mar 20, 2009 · 6 comments

Comments

@vstinner
Copy link
Member

BPO 5524
Nosy @loewis, @vstinner
Dependencies
  • bpo-4628: No universal newline support for compile() when using bytes
  • Files
  • open_script.patch
  • 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-03-31.16:15:29.853>
    created_at = <Date 2009-03-20.01:54:03.513>
    labels = []
    title = 'execfile() removed from Python3'
    updated_at = <Date 2009-03-31.16:15:29.782>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2009-03-31.16:15:29.782>
    actor = 'jhylton'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-03-31.16:15:29.853>
    closer = 'jhylton'
    components = []
    creation = <Date 2009-03-20.01:54:03.513>
    creator = 'vstinner'
    dependencies = ['4628']
    files = ['13380']
    hgrepos = []
    issue_num = 5524
    keywords = ['patch']
    message_count = 6.0
    messages = ['83845', '83853', '83858', '83885', '83932', '84821']
    nosy_count = 3.0
    nosy_names = ['loewis', 'jhylton', 'vstinner']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue5524'
    versions = ['Python 3.0', 'Python 3.1']

    @vstinner
    Copy link
    Member Author

    In "What’s New In Python 3.0" document, I can read "Removed
    execfile(). Instead of execfile(fn) use exec(open(fn).read())". The
    new syntax has two problems:

    • if the file is not encoding in UTF-8, we get an unicode error. Eg.
      see issue bpo-4282
    • exec() doesn't support newline different than \n, see issue bpo-4628

    We need a short function which opens the Python file with the right
    encoding. Get Python file encoding and open it with the right encoding
    is a command pattern.

    Attached patch proposes a function open_script() to open a Python
    script with the correct encoding. Using it, execfile() can be replaced
    by exec(open_script(fn).read()) which doesn't have to two binary file
    problems.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Mar 20, 2009

    -1. There is a much simpler solution to the problem: use exec(open(fn,
    "rb").read())

    @vstinner
    Copy link
    Member Author

    martin> There is a much simpler solution to the problem:
    martin> use exec(open(fn,"rb").read())

    Ok... but there is the newline issue: (self quote) "exec() doesn't support
    newline different than \n, see issue bpo-4628".

    And open_python() can be used for other usages than execfile() ;-)

    Note: tokenize.open_python() is maybe not the best module and/or function
    name.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Mar 20, 2009

    Ok... but there is the newline issue: (self quote) "exec() doesn't support
    newline different than \n, see issue bpo-4628".

    So that issue should get fixed, then.

    And open_python() can be used for other usages than execfile() ;-)

    Note: tokenize.open_python() is maybe not the best module and/or function
    name.

    I remain opposed to the entire concept.

    @vstinner
    Copy link
    Member Author

    > Ok... but there is the newline issue: (self quote)
    > "exec() doesn't support newline different than \n,
    > see issue bpo-4628".

    So that issue should get fixed, then.

    Ok, I will work in the other other issue. If bpo-4628 is fixed, this
    issue becomes meaningless ;-)

    @jhylton
    Copy link
    Mannequin

    jhylton mannequin commented Mar 31, 2009

    It doesn't seem helpful to leave this issue open, particularly since the
    title suggest there's a problem with execfile being removed and that's
    not going to change.

    @jhylton jhylton mannequin closed this as completed Mar 31, 2009
    @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
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant