Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute a default .py file in PyDev

I'm doing a Python project in Eclipse with PyDev. I have a "main" file and some "class" files. I primarily work in the classes, but I need to execute the code via the main file.

At the moment I need to either switch to the main file, or use the drop down menu of the run/debug-button to execute the main file. Pressing the button or using F11, just runs the class file (which is useless)

Is there a way to let PyDev always run a specific file in a project, or perhaps always run the last file executed (which probably will be the best solution).

Thanks in Advance :)

like image 582
Tobber Avatar asked Jan 20 '12 09:01

Tobber


People also ask

How do I run Python in PyDev?

Configure PyDevGo to Window → Preferences. In the Preferences window, expand PyDev and select Interpreter-Python. Click "New..." and type Python32 for the Interpreter name. For the Interpreter executable, browse to your copy of Python (C:\Program Files\Python32\python.exe), and press Open.

How do I run Python on Liclipse?

Running Python from within Eclipse Make sure your file ends in . py, and Eclipse will recognize it as Python code. Type in some Python code (for instance: print 2+2 ), then right-click on the Python file you've created and select Run As >> Python run .

Can we write Python code in Eclipse?

For Python development under Eclipse you can use the PyDev Plugin which is an open source project. Install PyDev via the Eclipse update manager via the following update site: http://pydev.org/updates.

How do I create a Python .PY file?

Create a Python fileIn the Project tool window, select the project root (typically, it is the root node in the project tree), right-click it, and select File | New .... Select the option Python File from the context menu, and then type the new filename. PyCharm creates a new Python file and opens it for editing.


1 Answers

Surely (relaunching the last launch was actually the default in in Eclipse 3.2, never understood why they changed that)...

You can have that back in the preferences at: window > preferences > Run/Debug > Launching and set the Launch Operation to Always launch the previously launched application.

So, Ctrl+F11 will relaunch the last launch and F11 will debug the last launch...

And to launch the file initially you may:

  • Use a shortcut: F9 to run the current opened file
  • Go to the menu: Alt + R + S + The number of the Run you wish (It can be Python, Jython, unit-test, etc).
  • If you are using unit-tests, you could use: Ctrl+F9 to run the unit-tests from the current module (and even selecting which tests should be run).
  • Relaunch some other launch you did previously: Alt + R + T and choose a previous launch to relaunch.
  • You may also launch in unit-test mode all files beneath a folder by right clicking the folder > run as > Python unit-test

(reference: http://pydev.org/manual_101_run.html)

And if you use unit-tests, you may also want to take a look at: Continuous unit testing with Pydev (Python and Eclipse)

like image 147
Fabio Zadrozny Avatar answered Oct 21 '22 17:10

Fabio Zadrozny