Cleanest way to run/debug python programs in windo

2019-02-02 05:25发布

问题:

Python for Windows by default comes with IDLE, which is the barest-bones IDE I've ever encountered. For editing files, I'll stick to emacs, thank you very much.

However, I want to run programs in some other shell than the crappy windows command prompt, which can't be widened to more than 80 characters.

IDLE lets me run programs in it if I open the file, then hit F5 (to go Run-> Run Module). I would rather like to just "run" the command, rather than going through the rigmarole of closing the emacs file, loading the IDLE file, etc. A scan of google and the IDLE docs doesn't seem to give much help about using IDLE's shell but not it's IDE.

Any advice from the stack overflow guys? Ideally I'd either like

  • advice on running programs using IDLE's shell

  • advice on other ways to run python programs in windows outside of IDLE or "cmd".

Thanks,

/YGA

回答1:

For an interactive interpreter, nothing beats IPython. It's superb. It's also free and open source. On Windows, you'll want to install the readline library. Instructions for that are on the IPython installation documentation.

Winpdb is my Python debugger of choice. It's free, open source, and cross platform (using wxWidgets for the GUI). I wrote a tutorial on how to use Winpdb to help get people started on using graphical debuggers.



回答2:

You can easily widen the Windows console by doing the following:

  • click the icon for the console window in the upper right
  • select Properties from the menu
  • click the Layout tab
  • change the Window Size > Width to 140

This can also be saved universally by changing the Defaults on the menu.



回答3:

I use eclipse with pydev. Eclipse can be sluggish, but I've become attached to integrated svn/cvs, block indent/unindent and run as unittest features. (Also has F5 run)

If your comfortable in emacs though I don't see any reason to make such a major change.

I suggest instead that you replace your 'crappy command prompt' with powershell. It's not as crappy.

(As mentioned by Soviut and The Dark - you can increase the buffer width/window size to more than 80 by title-bar>right-click>Properties>Buffer Width/Window Size edit even in crappy cmd)



回答4:

However, I want to run programs in some other shell than the crappy windows command prompt, which can't be widened to more than 80 characters.

Click on the system box (top-left) in the command prompt and click properties. In the layout tab you can set the width and height of the window and the width and height of the screen buffer. I recommend setting the screen buffer height to 9999 so you can scroll back through a long output.



回答5:

Wing IDE is awesome. They also have a free version.



回答6:

2017 Answer:

Try Visual Studio Code, it has great support for Python debugging, auto completion and more!

See this link for details: https://code.visualstudio.com/docs/languages/python#_debugging



回答7:

I edit my Python programs in EditPlus. I've configured a user tool that allows me to run my program and have its output appear in a frame below my editor window. My configuration will even let you double click on an exception lines in the output to jump directly to the file and line where the error occurred. You can grab the user tool configuration I use from here on the EditPlus wiki.

Perhaps there is similar functionality you can configure that allows you to run your program and display its output in your Emacs editor!?



回答8:

If you ever graduate to vim, you can just run the following command to start the program you're currently editing in an interactive shell:

:!python -i my_script.py


回答9:

I replaced cmd with Cygwin and Poderosa. May be a little overkill though, if the only problem you have with cmd is that it's a pain to resize.

Although you use Emacs instead of Vim, so I guess you're into overkill... ;-)