Custom module accessing variables outside of CP


I want run CP from within a python script and I’d like to know before I start writing custom modules if those modules will have access to variables in the outer, parent python script? If the answer is no then how can I pass variables to my custom modules from outside of a CP process? I can run a pipeline from another script using os.system or subprocess.Popen so I don’t need help with that part.

Thanks in advance! John

The outside Python process and inside Python process have different sets of globals so you have to think of some strategy other than variables to do what you want. One idea is to use environment variables, for instance in the outside one:

import os
os.environ"TALK_TO_CP"] = “HelloCP”

and in your module
import os
message = os.environ"TALK_TO_CP"]

Does that solve your problem?


Hi Lee,

Thanks for the quick reply. I’m new to python and haven’t used the os.environ function yet. Thanks for the suggestion. A quick check looks like it might only handle strings. Any idea if this will this work with python objects?