Different results when running script from IDLE versus Command Line

Casey T cpthomas at gmail.com
Wed Mar 12 19:10:06 CET 2008


I'm new to Python and I'm having some problems with getting different
results from my script when I run it from IDLE versus just double-
clicking the .py file and having it run through the command line.
Basically, my script reads some CSV files, assembles a text files,
then uploads that test file to an ftp site. When I run the script from
IDLE, everything works fine. But when it runs from the command line,
the file that gets uploaded is empty. It seems that it is creating a
new file to upload, rather than using the existing file (or at least
that's what I think is going on.) Below is my script. I apologize for
any ugly code. Thanks for your help.

import sys,os,linecache,csv,ftplib,time

starttime = time.time()

#Summary file assembling
currentdir = "//folder/"

reg_sum = open('reg_sum.txt','w')

for files in os.listdir(currentdir):
    reg_file = csv.reader(open(currentdir + files))
    for row in reg_file:
        reg_sum = open('reg_sum.txt','a')
        reg_sum.write(",".join(row) + ',\n')


#Summary file processing
coordList = [

coordList_index =
#coordList_index is a list containing

in_text = open('reg_sum.txt','r')

out_text = open('reg_out.txt','w')

out_text = open('reg_out.txt','a')

for line in in_text:
    split_line = line.split(',')
    if (split_line[0]) in coordList_index:
       i = coordList_index.index(split_line[0])
       coords = str(coordList[i][1]) + "," + str(coordList[i][2])
       last_update = str(split_line[2])
    print str(split_line[0])
    if split_line[1] == "1":
       out_text.write(split_line[0] + "<br>,Test1: " + last_update +
"," + coords + ",1" + "\n")
    elif split_line[1] == "0":
       out_text.write(split_line[0] + "<br>,Test2.<br>Last updated: "
+ last_update + ","  + coords + ",0" + "\n")
       out_text.write(split_line[0] + "<br>,No data.," + coords +


###Uploads file via FTP
s = ftplib.FTP('ftp.blah123.org,'user','pass')

s.storlines('STOR reg_out.txt', f)


print  "Processed in " + str(((time.time() - starttime) / 60) *60) + "
seconds!" #prints elapsed time

More information about the Python-list mailing list