i need to open a file but everytime i try opening it, i get a error, wel not really an error but it does't open. I have the name of the fles saved in the same location as the program itself, so all i do to try and open it is open(waitinglist, "r"), but it says that file could not be found. the file is saved at E:\Projects\Practical Projects\waitinglist.doc
ca anyone help me to ry and get this to work. here's the code i used.
def open_list(list_options):
# The fuction takes in an argument which should be the name of a file.
# It thens open the file and pulls information from it line by line. Each line represent a record
# Each line/ Record it sent to the format funtion where the data is processed into a list.
# Each sub list is then appended to the main list to form the complete file.
try:
x = open(list_options, "r")
except:
print "The file required could not be found. Try again and if the problem persist, contact the program designer"
return False
# The fist line in the file tells us how much records are in the file. This number is used as a
# basecase for the while loop.
record_no = x.readline()
record_no = (int(record_no)-1)
lis =[]
i=0
while i <= record_no:
y = x.readline()
record = format(y, [",", "\n"])
lis.append(record)
i+=1
x.close
return lis
def format(string, chars):
# This function takes in a string and turns it into a list.
# The sting contains different information in it. The information is cut from the string
# and placed into the list in a specific order (Top one, is first in list, last one is last)
list = []
i=0
while i <len(string):
if string in chars:
i+=1
else:
endval = ""
j=i
while j <len(string) and string[j] <> chars:
j+=1
endval = string[i:j]
list.append(endval)
i=j
return list
Chaosguy - To die would be an awefully big adventure.
ca anyone help me to ry and get this to work. here's the code i used.
def open_list(list_options):
# The fuction takes in an argument which should be the name of a file.
# It thens open the file and pulls information from it line by line. Each line represent a record
# Each line/ Record it sent to the format funtion where the data is processed into a list.
# Each sub list is then appended to the main list to form the complete file.
try:
x = open(list_options, "r")
except:
print "The file required could not be found. Try again and if the problem persist, contact the program designer"
return False
# The fist line in the file tells us how much records are in the file. This number is used as a
# basecase for the while loop.
record_no = x.readline()
record_no = (int(record_no)-1)
lis =[]
i=0
while i <= record_no:
y = x.readline()
record = format(y, [",", "\n"])
lis.append(record)
i+=1
x.close
return lis
def format(string, chars):
# This function takes in a string and turns it into a list.
# The sting contains different information in it. The information is cut from the string
# and placed into the list in a specific order (Top one, is first in list, last one is last)
list = []
i=0
while i <len(string):
if string in chars:
i+=1
else:
endval = ""
j=i
while j <len(string) and string[j] <> chars:
j+=1
endval = string[i:j]
list.append(endval)
i=j
return list
Chaosguy - To die would be an awefully big adventure.