1

I have two questions in regards to the PyDev (Python editor for Eclipse) and its interactive console.

Here is my current situation: whenever I run the interactive console (ctrl + alt + enter), the console requires that I then import the file in the project to use any functions in that file. Furthermore, when calling the function, I must put the file name in front of it. So, for example: I go to my properties for the project, go to the PyDev PYTHONPATH, and add a source folder for the project I am currently working on. By doing so, I can then import a file, let's call it "homework", into the interactive console. If my file has a function called "calculate", I will have to first type "import homework", then type "homework.calculate()" in order to use the said function. Otherwise, it won't work (I cannot simply call "calculate").

This brings me to my first question (#1): Why does this not apply for imported modules, such as "math" and such? Why do I need to do so much work for a local project file?

My second question is related (#2): How do I set-up my PyDev such that it automatically imports the current project's files into the interactive console? Or, even if I have to manually add my project file, how do I make it so I don't have to call the "file name" + "function name" in order to use the function?

Much help would be appreciated. Thank you.

Zhouster
  • 746
  • 3
  • 13
  • 23

1 Answers1

1

Actually, in PyDev, provided you have the PYTHONPATH all properly set, you should be able to do (considering your example: homework.calculate()):

calcu <- request code-completion and choose: calculate (homework)

Then it should add the import for you as well as the function you selected.

Aside from that, you'd have to write some code that iterated all your modules, made imports for that and loaded the tokens under the current context (which is not usually a good idea, as you'd have modules overriding names from other modules).

Also note that you can edit the initial set of commands that the interactive console executes at:

window > preferences > pydev > interactive console > initial interpreter commands

So, you may add more imports there which you'd like to have by default.

Fabio Zadrozny
  • 24,814
  • 4
  • 66
  • 78