Import Module

Gary Herron gherron at islandtraining.com
Thu May 20 10:20:15 EDT 2010


On 05/19/2010 09:40 AM, Harikrishnan R wrote:
> Hi ,
>      I have a file a.py contains
>
>      from one.two import abc
> --------------------------------------------
>      is there any way to find out  "one.two" the import Path of abc. ?
> I don't want one.two.abc . Any function or attribute which directly
> give one.two ?
>
> -Regards
>
>    

What's so hard about computing what you want from what your can get.

Since abc.__module__ gives gives you too much, trim it down -- perhaps 
even with os.path.splitext, although that's not what what splitext was 
meant for.

     os.path.splitext(abc.__module__)[0]


Gary Herron




More information about the Python-list mailing list