[Tutor] 'source' in python or preloading variables

John washakie at gmail.com
Sat Oct 27 14:49:40 CEST 2007


I have a file sitelocations:

STN_id[1]=AAA
STNlat[1]=58.800000
STNlon[1]=17.400000
STNelv[1]=20
STN_id[2]=BBB
STNlat[2]=42.450000
STNlon[2]=25.583333
STNelv[2]=2925

which in shell scripts I can simple 'source'. In Python I have to:
sitesFile=file('sitelocations','r')
sites=sitesFile.readlines()
i=0;
for l in sites:
        if i==0:
                STN_id.append(l.split('=')[1].strip('\n')); i+=1;
        elif i==1:
                STNlat.append(l.split('=')[1].strip('\n')); i+=1;
        elif i==2:
                STNlon.append(l.split('=')[1].strip('\n')); i+=1;
        else:
                STNelv.append(l.split('=')[1].strip('\n')); i=0;

Is there a better way??

Thanks!




-- 
Configuration
``````````````````````````
Plone 2.5.3-final,
CMF-1.6.4,
Zope (Zope 2.9.7-final, python 2.4.4, linux2),
Five 1.4.1,
Python 2.4.4 (#1, Jul 3 2007, 22:58:17) [GCC 4.1.1 20070105 (Red Hat
4.1.1-51)],
PIL 1.1.6
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071027/86852af9/attachment.htm 


More information about the Tutor mailing list