Get the directory of package

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 09 September 2013   #1
Get the directory of package

Hi everybody
I wonder if we can get the path to a package inside Maya? Like Os, or an user package which had been putted inside Maya's script folder?

Thanks
 
Old 09 September 2013   #2
The easiest solution would be to import the module and then print the __file__ method.

example:

import maya
import os
import your_custom_module

print maya.__file__
print os.__file__
print your_custom_module.__file__
 
Old 09 September 2013   #3
Are you trying to find the path of an active module, or the paths where modules may lie? Are you trying to find the path interactively in Maya or as part of your code?

Depending on what you need it for, you can look into python's inspect module:
http://docs.python.org/2/library/inspect.html

-- particularly, look into inspect.getfile() and inspect.currentframe() if you are trying to determine the source of your code at runtime.

If you are trying to access modules in subfolders, you can add a __init__.py file inside the subfolder to access it as a module: http://docs.python.org/2/tutorial/modules.html#packages

If you're just looking for paths that Maya will look for python scripts, the sys module will help:
import sys
for p in sys.path:
       print p
 
Old 09 September 2013   #4
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 01:12 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.