Update (2017): This article a bit outdated at this point. While the demonstrated techniques still work, currently my preferred way of writing Python would probably be in Visual Studio Code as an IDE. It is very easy to set it up to run the project by simply pressing F5, and also has an integrated terminal. If you prefer Aptana studio as your IDE you can find the tutorial here.

This post may not be necessarily game-development related, but I bet it's a nice piece of info to have for anyone who likes to setup fancy coding environments. Here we will use Notpad++ as coding environment, and set everything up so that we can have Python output with just two button presses. I go into quite a bit of hand-holding. Good thing is that if you read this, you'll be ble to set it up not only with python, but other compilers. Oh, and should you use IDLE? No, I want to show the general procedure and use a popular text editing tool. This is relevant only on Windows OS. Let's jump in!

1. Way of Notepad++

First you need to make sure you have Notepad++ installed. You can grab it from here: http://notepad-plus-plus.org/download/v6.3.html. If you don't have it already, shame on you. And while you're there, make sure to grab the compare plugin: http://sourceforge.net/projects/npp-compare/. If you want diff (graphic differences in two text files), you can always grab WinMerge: http://winmerge.org/, but this is perhaps quicker to just press Alt + D for two open tabs. Now that Notepad++ is installed, you can configure all kinds of things with it - say different colors for different tags in Settings > Style Configurator, format current tag by choosing Language etc. Whats more, you can configure it to run your code by pressing Run > Run. But first you have to install...

Python of course. Get it from here: http://www.python.org/getit/, install it and check if you can access the exe. That is, go Start > Run, type in cmd, and in there type in python. If you get something like

'python' is not recognized as an internal or external command, operable program or batch file.

...then you need to edit your path in Environment variables to include python.exe. See, when you typed in python shell looks for executable in your system "path", listed in Environment variable %Path%. So, right-click Computer choose Properties, and if on Windows 7 find Advanced system settings on the left. In System properties go Advanced, then Environment Variables, in System Variables find Path. Be very carefull here, but press Edit and add at the end the path to the folder where you installed Python, mine would be (not default):

B:\Instalacije Programa\Python 2.7\

Reopen cmd, and type python again. If you don't see something like below may Google help you :)

Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32

Now that env is set up, notice the python prompt is open. Press Ctrl+Z and press Enter to exit and return to cmd prompt.

Now we want to type some python code in Notepad++ and have it run. Find a working python example online, like here http://learnpythonthehardway.org/book/ex1.html, (my examples are from there) perhaps try it out in prompt as above, paste it in Notepad++, choose language. Now the magic happens, but first let's do it the "easier" way. Open Run > Run For now paste :

"B:\Instalacije Programa\Python 2.7\python.bat" "$(FULL_CURRENT_PATH)"

Remember, B:\Instalacije Programa\Python 2.7\ is the path where my python is installed, change it accordingly. What is python.bat? Well, we'll create it now. Go to that dir. Create a .txt file and name it python.bat of course, but first make sure you go into Folder and Search Options and uncheck Hide extensions for known file types. Then edit .bat file and paste in:

@ECHO OFF 
python.exe %1 
echo: 
pause 
@ECHO ON 

This tells Python to take as first argument that was passed to the .bat, that is $(FULL_CURRENT_PATH), which is full path to the current file in Notepad++. That's why it's important to save the Notepad++ file first as you'll get the error if it's not.

Now we should save settings for later. Again, in Run > Run makes settings like in image below (right window appears on pressing Save...):

Now in Run menu there should be a new entry on the bottom called Python Vanilla. Pressing it will call our script every time. However, say you close Notepad++ and want to edit that entry. It seems there is no option to do so, but... have no fear. You can always edit shortcuts.xml, which you get by accessing %appdata%/Notepad++ in explorer.

This is nothing original, you can find similar guides if you google a bit. However I was so not satisfied with this solution because the output is ugly, and I like using exteded console instead of cmd (sometimes just for the fun of it). Now lets upgrade to the "harder" way.

First you should to install TCC/LE. Basically what it does is extends CMD with additional variables and commands. It's not on par with powershell, but sometimes you can only work with cmd and this is a good tool. You don't need it at all in this procedure, but it's nice to install it now, since it ties nicely with other software. Grab it here: http://jpsoft.com/tccle-cmd-replacement.html. After you install it, run it. One thing I recommend doing is setting the annoying option of default cursor overstrike mode to off. In Tcc.exe prompt type in OPTION. GUI opens, go Command Line then select Initial Insert. Now you can close it, other settings are fine for me.

Next install Con Emu. Grab it here: http://code.google.com/p/conemu-maximus5/. It's a great and very customizable graphic console emulator, but it has no shell functions meaning it has no commands and veriables of its own. We have TCC/LE for that, anyway. Good news it "integrates" with it automatically (also with cmd and powershell), so when you open you are greeted with something like:

TCC LE 13.05.69 Windows 7 [Version 6.1.7600]

Try it yourself, type in:

echo I'm %_WINUSER!

There are many optins, and I'll show you my favourites. Get to settings by Right-clicking top of the window. First things first: background image :) - something like this and set options to tile:

Also choose Font Consolas, and add Italic for good measure. Also choose Solarized Light as color, or anything you like better.

Mark & Paste is really important, if you don't set it you'll have to hold modifiers to select text. Again, these are the settings that work for me.

It's also possible to set up different color schemes for different applications. Take a look:

There is only one thing remaining: set Notepad++ again to point ConEmu (not cmd) so that we get better output. Again, paste this in Run > Run:

"B:\Instalacije Programa\Con Emu\ConEmu64.exe" /Title "Python execution" /Dir "B:\My Docs\Learning\Python\Learn Python The Hard Way\" /Single /cmd python "$(FULL_CURRENT_PATH)"

Explanation:

"B:\Instalacije Programa\Con Emu\ConEmu64.exe" Full path to ConEmu exe (mine is 64-bit). Change as appropriate
/Title "Python execution" Title of the window that opens that holds results as a tab
/Dir "B:\My Docs\Learning\Python\Learn Python The Hard Way\" Woking dir. Optional. You can exclude this one actually.
/Single Open new tab on consequent re-runs, not new window
/cmd python "$(FULL_CURRENT_PATH)" Same as before

Good thing is now you don't have to pause in .bat, you get that by ConEmuC. Don't forget to save it and assign a keys shortcut to it, as before.

Here is my final result:

Not too bad, eh? Well, in the process you got youself a powefull teminal, shell and have learned some basic system operations. If you liked how this went feel free to leave a comment, or ask on similar topics. Know that it was mostly about the process, not the result.

 

Way of Sublime Text 2

Sublime Text 2 is a new star in the world of text editors. If you're a crazy text editor maniac, you're going to love it. It is so extensible and configurable. Also it can build in python natively (of course, you have to have it installed first), and display output in the same window (so far I haven't seen the option to change this though). It's also an "unlimited demo" version. Here's how it looks on me:

To get it to look like this you should first do a couple of things. Install it, of course, by grabbing it here: http://www.sublimetext.com/2, it looks really innocent. First package you should install is Package Control. After that, you can install most other pacakges with it (think repos). On this page you can see how: http://wbond.net/sublime_packages/package_control/installation. Then press Ctrl + Shift + P and start typnig: package control: install package. Here you get a list of packages you could install... Here are the ones I have, for basic use of this powerful editor:

  • BracketHighlighter
  • DayleReesColorSchemes
  • Emmet
  • PackageControl
  • PyV8
  • SFTP
  • SideBarEnhancements
  • SublimeFileDiffs-master
  • Sublimerge
  • Theme-Soda

Keep in mind this is only scratching the skin of what this editor can do. Color scheme I kept at iPlastic, for one simple reason: it differs elements nicely in .html files. Also, this is in my Settings  User:

{
"color_scheme": "Packages/Color Scheme - Default/iPlastic.tmTheme",
"fade_fold_buttons": false,
"font_size": 11.0,
"ignored_packages":
[
"Vintage"
],
"soda_classic_tabs": true,
"theme": "Soda Light.sublime-theme"
}

There it is. Happy coding people.