Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trouble with files

Status
Not open for further replies.

chaosguy

Programmer
Nov 5, 2005
45
0
0
VC
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.
 
sorry guys, i wasn't putting .txt at end. problem soved. um, i don't need help anymore, lol. bye

Chaosguy - To die would be an awefully big adventure.
 
The file name only is passed, the directory is not in the program path.
 
oh yeah i know. it doesn't ahve to have it. once it's in the same folder as python, but i'm awear that the full file name isn't there. thanks bye.

Chaosguy - To die would be an awefully big adventure.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top