473,385 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to "source" a file?

I have a set of configuration files that are expressed in
python. Users can set up triggers and callbacks as
python function calls.

Some of these functions have become shared between several
products, so I would like to factor out these functions into
a separate file.

Can someone give me a clue as to the best way to proceed?
I'm trying various combinations of import, but with no success.

Can someone loan me a clue?

Many TIA,
Mark

--
Mark Harrison
Pixar Animation studios
Jul 18 '05 #1
3 2321
Mark Harrison wrote:
Can someone give me a clue as to the best way to proceed?
I'm trying various combinations of import, but with no success.


What does "with no success" mean? What have you done, what have you
expected, what happened?

Mathias
Jul 18 '05 #2
Specifically, I'm confused why

def dfpostadd(name):
"""per-unit postprocessing step"""
sys.path.append('/my/config/path')
import dfacommon
dfacommon.addm(name)

works, but this doesn't:

sys.path.append('/my/config/path')
import dfacommon
def dfpostadd(name):
"""per-unit postprocessing step"""
dfacommon.addm(name)

which gives me:

msg=global name 'dfacommon' is not defined trace=[' File "<string>",
line 341, in doadd\n', ' File "/usr/anim/config/ndfd/mark.cfg",
line 55, in dfpostadd\n dfacommon.addm(name)\n']
Many TIA,
Mark
Jul 18 '05 #3
Mark Harrison wrote:
Specifically, I'm confused why

def dfpostadd(name):
"""per-unit postprocessing step"""
sys.path.append('/my/config/path')
import dfacommon
dfacommon.addm(name)

works, but this doesn't:

sys.path.append('/my/config/path')
import dfacommon
def dfpostadd(name):
"""per-unit postprocessing step"""
dfacommon.addm(name)

which gives me:

msg=global name 'dfacommon' is not defined trace=[' File "<string>",
line 341, in doadd\n', ' File "/usr/anim/config/ndfd/mark.cfg",
line 55, in dfpostadd\n dfacommon.addm(name)\n']


Strange. Is there any code later on in the file that removes dfacommon from
the module namespace? Something like this:

sys.path.append('/my/config/path')
import dfacommon
def dfpostadd(name):
"""per-unit postprocessing step"""
dfacommon.addm(name)

# ...other stuff here...

del dfacommon

Or maybe some functions are extracted from the config file and the module
itself is discarded, getting rid of the dfacommon global in the process. In
such cases, the first function works, because it imports and uses the module
immediately. The second function, however, depends on the name 'dfacommon'
available in global namespace. Normally this isn't a problem, but apparently
something unusual is going on with the namespaces here. I wonder how these
config files are used/imported...

Cheers,

--
Hans (ha**@zephyrfalcon.org)
http://zephyrfalcon.org/

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Phil Powell | last post by:
I'm sorry but I can't figure out how to explain this any better than this. In PHP we have a command "require()" that obtains a file and logically places it into another file. I cannot figure...
1
by: Harald Deischinger | last post by:
I am using a source file with the following style (I know it is not very beautiful but it is working): SRC1.cpp: static void vFoo() { // bla bla bla } static int iInit1(name, fun) { //...
18
by: Lorem Ipsum | last post by:
interesting! I just found a page in which Explorer's View Source does nothing! How did they do that?
0
by: David | last post by:
I have a C# app that quits periodically with the message "No source file given". Sometimes it will only run for an hour or two. Other time it will run for days before it quits. I've searched...
0
by: wildman | last post by:
Trying to read XML files from SSIS and load into SQL Server. I tested this before and it was working before I placed in a forevery contrainer. also, my simple xml file had to be retyped cause I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.