when I try to load a file using
fin=open("text.txt")
I get this error
Traceback (most recent call last):
File "C:/Python25/test.py", line 17, in <module>
fin=open("text.txt")
IOError: [Errno 2] No such file or directory: 'text.txt'
I know the file does exist, ive tried swapping between putting the file in my documents and the desktop.
Its driving me mad!
file opening error
Started by yamman13, May 18 2010 05:37 AM
4 replies to this topic
#1
Posted 18 May 2010 - 05:37 AM
|
|
|
#2
Posted 18 May 2010 - 05:59 AM
Maybe try
fin = open("text.txt", r)
Is the txt file and the python file in the same folder? Try including the full path if not.
fin = open("text.txt", r)
Is the txt file and the python file in the same folder? Try including the full path if not.
#3
Posted 18 May 2010 - 12:41 PM
Yea that was it cheers. I cant believe I missed something so blindingly obvious
#4
Posted 18 May 2010 - 01:57 PM
At least here (Linux), Python allows you to omit the "r", as it defaults to that. If you add an "w", as in open("a.txt", "w"), it will create the file if it doesn't exist.
#5
Guest_x42_*
Posted 03 June 2010 - 10:02 AM
Guest_x42_*
the reason why is that, "text.txt" is not the full name, you see, first you have to put "c:\" which is the drive for it to look in, then you have to put in instructions for what files to go through to ge to your file, so if you are running windows xp: "c:\Documents and Settings\your_user_name\My Documents\text.txt" this means that in the C drive there is a folder that is not in any other folders that is called "Documents and Settings" in it there is one to go into that is titled with your user name, then there is a folder in it called "My Documents" and in that there is a file called "text" and it has the file extension ".txt"


Sign In
Create Account


Back to top










