getting started, .py file

Peter Hansen peter at engcorp.com
Mon Feb 20 17:02:24 EST 2006


nibiery at hotmail.com wrote:
> I am just getting started with Python, and I think I may be thinking
> about it wrong. I'd like to be able to work interactively with some
> code that I've got in a file. The only interpreted language I have much
> experience with is Tcl/Tk, and in that I would use "source file.tcl" in
> the console to load my source. Is there a similar command in python? I
> know I can run my file as a script, but since I'm just experimenting
> with how the language works, I want to have more flexibility to be able
> to interactively check the contents of variables and define one piece
> at a time. Am I missing something obvious, or am I not thinking about
> Python properly?

Note that one useful thing you can do if you take Steve's first approach 
("import mycode") is to do "reload(mycode)" after you've made changes in 
a text editor and resaved your mycode.py file.  That will reload the 
module from the source, picking up whatever changes you've made.  Handy 
for some kinds of quick experimentation... (though often just typing 
stuff at the prompt and then integrating with your source after you've 
got it working is a more efficient approach).

-Peter




More information about the Python-list mailing list