I'm working on writing a script which would read a text file on the internet (or on my disk) and parse it for a latitude-longitude pair, and maybe some file name information. I've done some testing and I've been unable to import and use python's urllib2 or the built-in file operation open().
The code I have so far looks like this:
Code: Select all
input=open("coords.txt",'r')
m=input.readlines()
input.close()
l = m[0].strip().split(',')
#... loading the image data and adjusting panel properties
panel[0].setCenter(float(l[0]),float(l[1]),scale=5)
#... saving the file
It seems the input=open() line is the only line causing problems. The script works just fine when floats are hard-coded into the setCenter() function. According to this documentation I found, what I'm doing should work, but the script doesn't save the file. So, I'm not sure to what extent the code works or if it just errors out. The script is running in cmd on Windows 7 from python as a subprocess.
How do I properly read data from a text file into a script?
Thanks,
Kalassak