[BangPypers] Module question

Heshan Suriyaarachchi heshan.suri at gmail.com
Tue Sep 2 08:22:35 CEST 2008


Hi Abhinav,
       I managed to overcome the problem.
Thanx :)

On Tue, Sep 2, 2008 at 11:03 AM, abhinav sarkar <abhinav.sarkar at gmail.com>wrote:

>
>
> On Tue, Sep 2, 2008 at 10:51 AM, Abhinav Sarkar <abhinav.sarkar at gmail.com>wrote:
>
>> Heshan Suriyaarachchi wrote:
>>
>>> Hi,
>>>    One of my scripts returns a module like below.
>>> <module 'annotationScript' from
>>> '/home/heshan/repo/scripts/annotationScript.py'>
>>>     What I need to do is to extract the full path of the location of the
>>> script as string. i.e. '/home/heshan/repo/scripts/annotationScript.py' .
>>> Since I am dynamically loading the script, it's name and full path may vary.
>>> Can you suggest me a mechanism to extract the full path from the above data
>>> structure.
>>> --
>>> Regards,
>>> Heshan Suriyaarachchi
>>>
>>> http://heshans.blogspot.com/
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> BangPypers mailing list
>>> BangPypers at python.org
>>> http://mail.python.org/mailman/listinfo/bangpypers
>>>
>>>
>> Hi,
>> __path__ attribute of module contains the path of file.
>> >>> import lastfm
>> >>> lastfm.__path__
>> ['c:\\python25\\lib\\site-packages\\lastfm-0.1-py2.5.egg\\lastfm']
>>
>> I hope it helps.
>> Cheers,
>>
>> --
>> Abhinav Sarkar
>> Fair Isaac India
>>
>> Mobile:+91-9731596137
>> Office: +91-8041371605
>>
>> Web: http://claimid.com/abhin4v
>> Twitter: http://twitter.com/abhin4v
>> ---------
>> The world is a book, those who do not travel read only one page.
>>
>>
> Hi,
> I was mistaken in last reply. __path__ attribute exists only for packages.
> You should use __file__ attribute. It works for packages and modules too.
>
> >>> import lastfm
> >>> from lastfm import api
> >>> api.__file__
> 'c:\\python25\\lib\\site-packages\\lastfm-0.1-py2.5.egg\\lastfm\\api.pyc'
> >>> lastfm.__file__
>
> 'c:\\python25\\lib\\site-packages\\lastfm-0.1-py2.5.egg\\lastfm\\__init__.pyc'
>
>
> Cheers
> --
> Abhinav Sarkar
> Fair Isaac India
>
> Mobile:+91-9731596137
> Office: +91-8041371605
>
> Web: http://claimid.com/abhin4v
> Twitter: http://twitter.com/abhin4v
> ---------
> The world is a book, those who do not travel read only one page.
>
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
>


-- 
Regards,
Heshan Suriyaarachchi

http://heshans.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/bangpypers/attachments/20080902/0115898d/attachment-0001.htm>


More information about the BangPypers mailing list