I am using automnation desk to run my python scripts.
It supports interpreter ver 2.2

I have some script common for almost all other script files of my application.
this common script is saved as CommonCalls.py and is on python search path.

I am using some ref. to a file path in CommonCalls.py and in other script files which import CommonCalls

If for some reason I need to change ref. path I need to change it into CommonCalls.py too.I want to avoid this

can anyone tell me is it possible to refer some parameter from importer.
if yes please explain the way

Thank you

Recommended Answers

All 5 Replies

I can not quite figure out what you want to do. I wrote these little test files. Test1.py contains a variable I want to use in Testing1.py.

Test1.py:

# test module, save as test1.py

test_path = "test1234"

Testing1.py:

# testing module test1.py
import test1

print test1.test_path

I am thinking this would work like the situation you told. What do you like to change?

I am sorry I was out and so could not reply in time

what exactly i am looking for is in reverse way

is it possible to define test_path = "test1234" in testing module
and can be accessed by test1.py

so that i can provide some browsing interface for file path selection for
test_path in testing file

Thank you for the reply

I am sorry I was out and so could not reply in time

what exactly i am looking for is in reverse way

is it possible to define test_path = "test1234" in testing module
and can be accessed by test1.py

so that i can provide some browsing interface for file path selection for
test_path in testing file

Thank you for the reply

You could save test_path info in file that is opened by test1.py every time it is imported/ativated. Make sure there is default path, in case the file does not exist.

Bumsfeld is correct, the easiest way to communicate to a module is with a shared file. If your variable is the name for an object like a list, then you best use pickle to save and retrieve the whole object.

To find out the folder where your module is located use ...

# get the path of a module (here module calendar):
import calendar
import os
print os.path.dirname(calendar.__file__)

In your case create the shared file name this way ...

import CommonCalls
import os
# producing the file name for a shared file ...
filename = os.path.join(os.path.dirname(CommonCalls.__file__), "shared1.dat")
print filename  # test it

In CommonCalls.py use simply ...

filename = "shared1.dat"

Bumsfeld thans for realy useful suggestion

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.