[Sidefx-houdini-list] Python modules scope in Houdini

Pablo Giménez pablogipi at gmail.com
Wed May 11 19:05:23 EDT 2011


Thanks for the info Graham.
My package runs several initialization routines that I want to run
only when houdini is started, so using the __main__ statement to
access them from other scripts is great.

2011/4/27 Graham Thompson <captainhammy at gmail.com>:
> They aren't really shared.  The main namespace is the one accessible
> from the Python Shell windows and is the one setup when you do things
> in the pythonrc.py file.  Parameter expressions, tools, parameter
> expressions and callbacks use different namespaces.  For example, the
> parm expression one by default does an 'from hou import *'.  Most
> don't have anything special though.  In order to use things out of the
> main namespace you need to have the following  'import __main__' and
> then call '__main__.mymodule.myfunc()'.  This works from all the other
> namespaces.
>
> Some more details, mainly for parameter expressions but applicable to
> things such as Python modules or other event handlers:
>
> http://www.sidefx.com/docs/houdini11.0/hom/expressions#id190985
>
> 2011/4/26 Pablo Giménez <pablogipi at gmail.com>:
>> Hi all.
>> I have a Python package with several modules which I load using  in my
>> $HOME/houdini11/scripts/pythonrc.py
>> Basically I have just one line>
>> import myPackage
>> Well this package has a __init__.py script with seveal stataments to
>> be executed on initialization.
>> I know that for the same Python session modules are loaded just one
>> time, so if you import it several times it will keep only the first
>> intance.
>> But I am not what is the scope of the Python inerpreter launched by
>> Houdini. The one you use when you open the Python console.
>> For instance if I a want to use a function from this package for a
>> menu script for a parameter I have to import my package again, whereas
>> if I use it in a Python console I dont need to do it.
>> So I am wondering if Houdini shares the same python session across all
>> the places where python can be used, or are situations where the
>> python session is diferent and a new interpreter is launched.
>> thanks
>>
>> --
>> Un saludo
>> Best Regards
>> Pablo Giménez
>> _______________________________________________
>> Sidefx-houdini-list mailing list
>> Sidefx-houdini-list at sidefx.com
>> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
>>
> _______________________________________________
> Sidefx-houdini-list mailing list
> Sidefx-houdini-list at sidefx.com
> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
>



-- 
Un saludo
Best Regards
Pablo Giménez



More information about the Sidefx-houdini-list mailing list