Anything similar to definition file?

Philip Swartzleonard starx at pacbell.net
Thu Jan 17 00:29:33 EST 2002


Ozone Hole near South Pole || Wed 16 Jan 2002 06:23:21p: 

> Hi, 
> 
> I am writing a robot controlling script in python.  The status info of 
> the robot is stored as in a list: [ [rec1], [rec2],.... [recN] ] In
> each rec, rec= [ sampleID, pos_x, pos_y, pos_z, force_r, force_t, ....] 
> 
> As the program is reasonable large, the algorithms are broken into a 
> number of files. To make the code a bit easy to read, I would like to 
> refer say, the y-pos at the 2033 rec as rec[2033][pos_y], rather than 
> rec[2033][2] #pos_y. 
> 
> At this moment, I need to include the following header to each file: 
> #record fields sampleID,pos_x,pos_y ...=0,1,2 ....... 
> 
> Does python have anything similar to a header file in C such that I can
> do, say, import myConfig, in each my file instead of repeating the
> above n times? 

Well, you could make a file like this:

    	#rec_fields.py
    	sampleID = 0
    	pos_x = 1
    	#or whatever you do to set up these names

and then in your main file:

    	from rec_fields import *
    	...
    	rec[2033][pos_x]

The only problem is possibly namespace polution, if you want to avoid this 
another method would be:

    	import rec_fields as rf #i think this is the syntax
    	...
    	rec[2033][rf.pos_X]

Which would give you a better grouping. There are at least a few other 
ways, like class attributes, but this should give you a start =)


-- 
Philip Sw "Starweaver" [rasx] :: <nothing> 



More information about the Python-list mailing list