Find the location of a loaded module

Aaron Scott aaron.hildebrandt at gmail.com
Fri Feb 20 17:44:21 EST 2009


And finally, an epilogue.

So, the problem lies with how Python cached the modules in memory.
Yes, the modules were in two different locations and yes, the one that
I specified using its direct path should be the one loaded. The
problem is, the module isn't always loaded -- if it's already in
memory, it'll use that instead. And since the modules had the same
name, Python wouldn't distinguish between them, even though they
weren't exactly the same. So, loading the module act1/story would load
act1/story. Then, loading the module act2/story would use the story
module already in memory. Of course, this made the problem hard to
pinpoint, since memory is a fickle thing, and the results weren't
always reproducible.

The final solution? Renaming the 'story' modules to 'story_1' and
'story_2'... and importing them via 'exec("from story_"+modulename+"
import game")'.

Will I go to hell for this 'solution'? Probably. But hey, it means I
can go home tonight instead of spending all evening at the office
hitting my head against the wall. I'll come back to it Monday and try
to figure out a more reasonable solution.



More information about the Python-list mailing list