Issue
I'm having problems using a looper script to run a main script several times. The main script runs on it's own and produces the desired output. Now, I want to run the script three times using the following loop:
array = ['case1','case2','case3']
for i in range(0,len(array)):
exec(open('mainscript.py').read())
It correcly opens and runs the first part of the script (several print statements end up on my screen). However, when I try to load a file with the name 'Coördinates4hoog' it can't find the file:
FileNotFoundError: [Errno 2] No such file or directory: 'path\Coördinates4hoog'
In this case I have changed the input files (which is not desirable but I thought it would be an easy fix). I know it is not the best choice to have signs like ö in the file name but in this case I'm working forward on previously made scripts and datafiles.
The point is, further in the script it loads latitude/longitude data with the ± sign. I can't change this datatype as it is repeatedly retreived from external databases. I get the following error:
KeyError: "['Latitude ±dd,dddddd' 'Longitude ±ddd,dddddd'] not in index"
It seems the looper script does not recognize these special signs even though it correctly runs the main script from the top (which is working on it's own). Any experience with this?
Solution
In this case, changing the special symbols to it's unicode character worked for me. So if you run into a similar problem use a similar approach.
So:
df_road_coords = pd.read_pickle(filefolder + 'Coördinates4hoog')road
Becomes:
df_road_coords = pd.read_pickle(filefolder + 'Co'+u"\u00F6"+'rdinates4hoog')
And:
adresses.loc[:,'(Latitude ±dd,dddddd, Longitude ±ddd,dddddd)'] = df_receivers[['Latitude ±dd,dddddd', 'Longitude ±ddd,dddddd']].apply(lambda x : '({},{})'.format(x[0],x[1]), axis=1)
Becomes:
adresses.loc[:,'(Latitude '+u"\u00B1"+'dd,dddddd, Longitude '+u"\u00B1"+'ddd,dddddd)'] = df_receivers[['Latitude '+u"\u00B1"+'dd,dddddd', 'Longitude '+u"\u00B1"+'ddd,dddddd']].apply(lambda x : '({},{})'.format(x[0],x[1]), axis=1)
For me, it's still abracadabra how a looperscript using same modules and versions can't handle the symbols in another script which is running on it's own.
Answered By - Bollehenk
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.