Hi,
I have a script that pulls data off the web based on data in a text file. The text file and script are in the same directory. The values from the script are read into a list. The list is then used in some conditional statements.
The text file has four lines each containing a textual code. So the resulting list has four values.
When the script is run it doesn't read past the 3rd value and gives the following traceback.
Usage: test.py [options]
test.py: error: ticker file Otickers.txt not found
Traceback (most recent call last):
File "C:\Python25\test.py", line 75, in <module>
parser.error("ticker file %s not found" % (tickerfile,))
File "C:\Python25\lib\optparse.py", line 1562, in error
self.exit(2, "%s: error: %s\n" % (self.get_prog_name(), msg))
File "C:\Python25\lib\optparse.py", line 1552, in exit
sys.exit(status)
SystemExit: 2
When I run the script with a debugger it gives me a connection reset by peer error and the following traceback. With a debugger it doesn't read past the first value.
Debugger:
Usage: test.py [options]
test.py: error: ticker file Otickers.txt not found
Traceback (most recent call last):
File "C:\Python25\lib\idlelib\Debugger.py", line 67, in run
return self.idb.run(*args)
File "C:\Python25\lib\bdb.py", line 366, in run
exec cmd in globals, locals
File "C:\Python25\test.py", line 75, in <module>
parser.error("ticker file %s not found" % (tickerfile,))
File "C:\Python25\lib\optparse.py", line 1562, in error
self.exit(2, "%s: error: %s\n" % (self.get_prog_name(), msg))
File "C:\Python25\lib\optparse.py", line 1552, in exit
sys.exit(status)
SystemExit: 2
Here is the basic code:
import urllib, datetime, sys
from optparse import OptionParser
if __name__ == '__main__':
parser = OptionParser()
parser.add_option("-f", "--file", dest="tfile", action="store", default = "t.txt",
help="read list from file")
(options, args) = parser.parse_args()
tfile = options.tfile
try:
file = open(tfile, 'r')
t = file.readlines()
for i in range(len(t)):
if t[i].rstrip('\n') == "TUE":
f = "tues"
d = "2"
print "f:", f
if t[i].rstrip('\n') == "MON":
f = "mon,"
d = "1"
print "f:", f
file.close()
data = urllib.urlopen(url)
for l in data:
if l.find(f) != -1:
r = l.split(',')
x = 2
while x < 4:
<<do something>>
x = x + 1
print "***********************************************************************************************************************"
except:
parser.error("t file %s not found" % (tfile,))
raise SystemExit
Thank you.