Newbie edit/compile/run cycle question

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Sun Dec 9 09:30:10 EST 2007


MartinRinehart at gmail.com a écrit :
> Thanks for all the help. Thought I'd spend my newbie days right in the
> Python shell (there's lots to test when you're just starting) but I
> guess that's not going to happen.
> 
> Everyone told me to get out of the Python shell, one way or another.

Everyone told you to not use the shell that way - which is not exactly 
the same thing. The shell is just great for exploring things. Like 
quicly testing APIs, expressions, syntax etc before or while coding, or 
inspecting the state after execution of your code (using the -i option), 
  etc... A common (AFAICT) practice is to have some 'test setup' code in 
a .py file, that you use to import the modules under test and init a 
couple vars, then launch this script with the -i option. Emacs 
python-mode let you start a python shell in another frame, and eval 
either your whole file or just parts of it in this shell.

> OK. But this means that every execution must first load Python, then
> import my stuff.

Just like it does with Java - but it might be much faster.

> Import becoming a NOP after first use in the shell is
> a six-legged feature, at best.

import becoming (almost) a NOP after first effective import is the 
RightThing(tm) to do. If you want to reload a module, you have to ask 
for it explicitely - using reload(module). But this won't affect already 
instanciated objects, and can lead to very strange situations - hence 
the common pattern of the setup script + the -i option.



More information about the Python-list mailing list