+1 on that, Judah.
Storing them in the __init__.py really does offer an excellent way to
organize by scope.


On Wed, Jan 25, 2012 at 2:03 PM, Judah Baron <judah.ba...@gmail.com> wrote:

> Additionally, and this might not apply to your situation until you have
> more of a system in place but, many of the constants that you might be
> interested in are best stored in some modular context. That is, you may
> have a number of settings that really belong in your export package, for
> instance. So instead of making them truely detached and "global" you can
> put them in your export __init__. When you need to retrieve this value it
> would then look something like the following:
>
> ## export.__init__
>
> PROCESSOR_EXE = "someTool.exe"
>
>
> ---------------------------------------------------------------------------------------------------------------------------------
> ## Any other implementation file
>
> import os
> import subprocess
> import parentPackage
>
> processorPath = os.path.join( toolPath,
> 'bin', parentPackage.export.PROCESSOR_EXE )
> if os.path.exists(processorPath):
>     subprocess.Popen( processorPath, *localArgs... )
>
> This will give your "global" variables/constants a meaningful scope. An
> added benefit of doing this is the completion provided in most  IDEs worth
> using. This may seem trivial, but it saves a lot of time when you have a
> large system of packages working together and lots of settings per package.
>
> For values that are not specific to a particular module, but are used by
> the system in general, you can put them in parentPackage, or an equivalent.
>
> -Judah
>
>
> On Wed, Jan 25, 2012 at 1:38 PM, Justin Israel <justinisr...@gmail.com>wrote:
>
>> I think that __main__ would be a very strange and unpredictable place to
>> store shared data in your environment.
>> If what you are after is a globals module to share settings, you could
>> try something like this....
>>
>> ## testConstants.py ##
>> BAR="foo"
>>
>> ## testScriptA.py ##
>> import testConstants
>>
>> print "BAR=", testConstants.BAR
>> testConstants.BAR = "blah"
>> testConstants.FOO = "bar"
>>
>> ## testScriptB.py ##
>> import testConstants
>>
>> print "BAR=",testConstants.BAR
>> print "FOO=",testConstants.FOO
>>
>>
>> # And when we try them out....
>> >>> import testScriptA
>>
>> BAR= foo
>>
>>
>> >>> import testScriptB
>>
>> BAR= blah
>>
>> FOO= bar
>>
>>
>>
>> Because modules are only imported once, importing your constants module
>> in multiple scripts will all reference the same module. You can then access
>> all the objects within that module.
>>
>>
>>
>>
>> On Tue, Jan 24, 2012 at 3:45 AM, m.dresch...@bigpoint.net <
>> m.dresch...@bigpoint.net> wrote:
>>
>>> Hi,
>>>
>>> I have a question regarding the storage of data in Maya that should be
>>> available in all my python scripts.
>>> I found the "__main__" class and added an (immutable) variable to it
>>> in the userSetup.py file.
>>>
>>> With this setup I can access the variable in all my scripts.
>>> Do some of you guys have experience with this? Is it ok to store data
>>> in __main__ or does it have implications
>>> I don't know?
>>>
>>> Thank you very much,
>>>
>>> cheers,
>>>
>>> --
>>> Malte Dreschert
>>> Senior Technical Artist @ Bigpoint
>>>
>>> --
>>> view archives: http://groups.google.com/group/python_inside_maya
>>> change your subscription settings:
>>> http://groups.google.com/group/python_inside_maya/subscribe
>>>
>>
>>  --
>> view archives: http://groups.google.com/group/python_inside_maya
>> change your subscription settings:
>> http://groups.google.com/group/python_inside_maya/subscribe
>>
>
>  --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings:
> http://groups.google.com/group/python_inside_maya/subscribe
>

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe

Reply via email to