module path?

Dave Angel davea at ieee.org
Mon Sep 28 20:22:42 EDT 2009


akonsu wrote:
> hello,
>
> is there a way to determine the file location of a loaded module?
> assuming it is not built in.
>
> import settings
> print settings
>
> produces: <module 'settings' from 'd:\ko\mysite\settings.pyc'>
>
> i would like to get to this path somehow other than by parsing the
> string representation of the module. is there a property on
> types.ModuleType? i could not find anything...
>
> thanks
> konstantin
>
>   
The property is called __file__

So in this case,    filename = settings.__file__





More information about the Python-list mailing list