how to load files in python
Posted
by
Alvaro
on Stack Overflow
See other posts from Stack Overflow
or by Alvaro
Published on 2012-11-13T22:39:27Z
Indexed on
2012/11/13
23:00 UTC
Read the original article
Hit count: 269
python
|python-2.7
I'm fairly new to python and would like some help on properly loading separate files. My codes purpose is to open a given file, search for customers of that file by the state or state abbreviation. However, i have a separate function to open a separate file where i have (name of state):(state abbreviation) Thanks.
def file_state_search(fileid, state):
z=0
indx = 0
while z<25:
line=fileid.readline()
data_list = ("Name:", "Address:", "City:", "State:", "Zipcode:")
line_split = line.split(":")
if state in line:
while indx<5:
print data_list[indx], line_split[indx]
indx = indx + 1
elif state not in line:
z = z + 1
def state_convert(fileid, state):
line2=in_file2.readline()
while state in line2:
print line2
x=1
while x==1:
print "Choose an option:"
print
print "Option '1': Search Record By State"
print
option = raw_input("Enter an option:")
print
if option == "1":
state = raw_input("Enter A State:")
in_file = open("AdrData.txt", 'r')
line=in_file.readline()
print
in_file2 = open("States.txt", 'r')
line2=in_file2.readline()
converted_state = state_convert(in_file2, state)
print converted_state
state_find = file_state_search(in_file, state)
print state_find
x=raw_input("Enter '1' to continue, Enter '2' to stop: ")
x=int(x)
By the way, my first import statement works, for whatever reason my second one doesn't. Edit: My question is, what am i doing wrong in my state_convert function.
© Stack Overflow or respective owner