1

Possible Duplicate:
reload (update) a .py file in the interpreter

I test some of my classes from Python in a terminal and I came across this issue.

If I test something and find a bug in a code, when I correct it in any text editor, then I find myself closing the python shell where I did my testing, then removing the .pyc file, and finally reopening the python shell and run the test all over again.

Is there any way for the system to automatically update the code and recompile it if necessary so I don't have to constantly repeat the procedure I just described.

Thank you

Community
  • 1
  • 1
miki725
  • 27,207
  • 17
  • 105
  • 121

2 Answers2

3

this question is very similar and the answers tell you how do do the auto reloading stuff with ipython:

reload (update) a module file in the interpreter

Community
  • 1
  • 1
Gryphius
  • 75,626
  • 6
  • 48
  • 54
0

If your code is simple, your best bet is making changes in an editor, and re-running the program from scratch each time.

If you happen to have input/raw_input commands, merely make a test harness. unittest and doctest can also be useful.

You don't need to remove the .pyc file, or even if you did you can use the -B flag to avoid making them in the first place.

ninjagecko
  • 88,546
  • 24
  • 137
  • 145