Python Development Tricks
There are a few best practices which will rapidly accelerate your iterative development / testing cycle within Python. Simply put, they are:
- download and install PyPE (follow this link), a code editor optimized for Python syntax
- set up your machine to automatically associate *.py files with PyPE so they will open on double-click.
- download and install CommandHere (aka "Open Command Window Here") (follow this link), a utility for quick-launching path-local command prompts within Windows (Vista has this built in, see below)
- learn simple keyboard shortcuts within the CMD window (see TIPS, below)
So, a typical development session will go as follows:
- double click on the source code file you wish to work on, which will open it in PyPE.
- iterate your code. Hit Ctrl-S (Save).
- right-click on the folder icon at upper left of the window (for Vista: shift-click on the folder icon in lower left), and select "Open Command Window Here". This will open a CMD prompt with the path set to your active development directory.
- type:
ppython MyProject.py
and hit ENTER. This will launch the Panda-specific version of Python (with all Panda associations already established), and launch your specific application in a separate window.
- TIP: Use in the built in "TAB-completion" functionality of the CMD window. Just type in the first few letters of yoru filename, and hit TAB; your full filename will be auto-completed. To cycle through multiple files, simply hit TAB repeatedly until your desired file shows up.
- Pay attention to what shows up in the CMD window. Python and Panda both have excellent debugging support built in, and errors, when they occur, are very clearly articulated within this window.
- It is also good practice to use
printstatements within your code while debugging. The output from these statements is relayed in real-time to the CMD window. - Once you've tested your program, close the program window (keep the CMD window open), and edit your code some more.
- TIP: seconds, minutes, or hours later, when you are ready to test another iteration of your code:
- CTRL-S to save your code
- ALT-TAB to swicth to the CMD window,
- UP ARROW to auto-fill the last command you entered
- ENTER to launch your iterated application in a new window.
- Test, Iterate and repeat. :) Have fun.
»
- Printer-friendly version
- Login or register to post comments
