Question: each unit test I'm running is writing python code out to a file, then importing it as a module. The problem is that the code changes but further import statements don't modify the module.

I think what I need is a way to ether force a reload on a module or clear the internal bytecode cache. Any ideas?

Thanks!

Answer: 
Use [`reload()`](http://docs.python.org/library/functions.html#reload).

> 
> Reload a previously imported module.
>  The argument must be a module object,
>  so it must have been successfully
>  imported before. This is useful if you
>  have edited the module source file
>  using an external editor and want to
>  try out the new version without
>  leaving the Python interpreter. The
>  return value is the module object (the
>  same as the module argument).
> 
> 
> 

However, the module needs to be already loaded. A workaround is to handle the resulting `NameError`:

```
try:
    reload(math)
except NameError:
    import math

```
Ran into a similar situation.
Later on found that the white space indentation technique used matters.
Especially on windows platforms, ensure that a uniform technique is adapted 
throughout the module i.e., either use tab or spaces exclusively.