Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7789331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:15:57+00:00 2026-06-01T21:15:57+00:00

There’s a problem in Pydev 2.5 and Python 3.2 with trying to load the

  • 0

There’s a problem in Pydev 2.5 and Python 3.2 with trying to load the module contents “into” the interactive console: when you hit Ctrl+Alt+Enter, Pydev fires execfile(filename) instead of exec(compile(open(filename).read(), filename, ‘exec’), globals, locals) – the latter being execfile()’s replacement in Python 3+…

So, how to change this behaviour?

ETA: to be a bit more concrete, things go like this: I create a new PyDev Module, say ‘test.py’, write some simple function def f(n): print(n), hit Ctrl+Alt+Enter, then I select “Console for currently active editor” and Python 3.2 interpreter, interactive console wakes up, and then I get this:

>>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
PyDev console: using default backend (IPython not available).
C:\Program Files (x86)\Python\3.2\python.exe 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)]

>>> execfile('C:\\testy.py')
>>> f(1)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'f' is not defined

As you can see, it still uses execfile() instead of exec(), that replaced it in Python 3+…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:15:59+00:00Added an answer on June 1, 2026 at 9:15 pm

    EDIT:

    The actual problem is that the execfile is not getting the proper globals in the PyDev redefinition. So, if the execfile did execfile(‘my_file’, globals()), it would work… I’ll change the implementation of PyDev so that if the globals is not passed, it’ll do:

    if glob is None:
        import sys
        glob = sys._getframe().f_back.f_globals
    

    (you can fix that in your local install at plugins/org.python.pydev_XXX/PySrc/_pydev_execfile.py and it should work — please let me know if it doesn’t).


    INITIAL ANSWER:

    That’s not possible, but PyDev does redefine execfile when you’re in its console on Python 3, so, it should still work… is that not working for you for some reason?

    Also, the replacement: exec(compile(open(filename).read(), filename, ‘exec’), globals, locals) is broken for some situations in Python 3.

    The actual redefinition (which should work in all situations and is available in PyDev) is:

    #We must redefine it in Py3k if it's not already there
    def execfile(file, glob=None, loc=None):
        if glob is None:
            glob = globals()
        if loc is None:
            loc = glob
        stream = open(file, 'rb')
        try:
            encoding = None
            #Get encoding!
            for _i in range(2):
                line = stream.readline() #Should not raise an exception even if there are no more contents
                #Must be a comment line
                if line.strip().startswith(b'#'):
                    #Don't import re if there's no chance that there's an encoding in the line
                    if b'coding' in line:
                        import re
                        p = re.search(br"coding[:=]\s*([-\w.]+)", line)
                        if p:
                            try:
                                encoding = p.group(1).decode('ascii')
                                break
                            except:
                                encoding = None
        finally:
            stream.close()
    
        if encoding:
            stream = open(file, encoding=encoding)
        else:
            stream = open(file)
        try:
            contents = stream.read()
        finally:
            stream.close()
    
        exec(compile(contents+"\n", file, 'exec'), glob, loc) #execute the script
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There seem to be many ways to define singletons in Python. Is there a
There is a text file with 1,000,000 lines of code floating around and Ctrl+F
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
There is a conversion process that is needed when migrating Visual Studio 2005 web
There are two weird operators in C#: the true operator the false operator If
There are two popular closure styles in javascript. The first I call anonymous constructor
There is previous little on the google on this subject other than people asking
There are a few ways to get class-like behavior in javascript, the most common
There are numerous Agile software development methods. Which ones have you used in practice

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.