views:

318

answers:

1

I'm trying to use Python's easygui module to select a file and then insert it's name into a program I wrote (see code below). So I want to insert filename 1 and 2 where it says insert filename1, etc.. Any help would be greatly appreciated. Thanks!

import easygui
import csv

msg='none'
title='select a 90m distance csv file'
filetypes=['*.csv']
default='*'

filename1= easygui.fileopenbox()
filename2= easygui.fileopenbox()

dist90m_GIS_filename=(open('**insert filename1'**,'rb'))
datafile_filename=(open(**insert filename2'**,'rb'))

GIS_FH=csv.reader(dist90m_GIS_filename)
DF_FH=csv.reader(datafile_filename)

dist90m=[]
for line in GIS_FH:
    dist90m.append(line[3])

data1=[]
data2=[]
for line in DF_FH:
    data1.append(','.join(line[0:57]))
    data2.append(','.join(line[58:63]))

outfile=(open('X:\\herring_schools\\python_tests\\excel_test_out.csv','w'))
i=0
for row in data1:
    row=row+','+dist90m[i]+','+data2[i]+'\n'
    outfile.write(row)
    i=i+1
outfile.close()
+1  A: 

I'm going to assume you're new to programming. If I misunderstood your question, I apologize.

In your code, after the lines:

filename1 = easygui.fileopenbox()
filename2 = easygui.fileopenbox()

The selected file names are stored in the variables filename1 and filename2. You can use those variables to open file handles like this:

dist90m_GIS_filename=(open(filename1,'rb'))
datafile_filename=(open(filename2,'rb'))

Notice how I simply wrote filename1 where you wrote **insert filename1**. This is the whole point of variables. You use them where you need their value.

itsadok