Reputation: 2541
I'm totally a noob at computer languages.
In my school I downloaded a file called color.txt Then I was suppose to do some programming involving the file......
import os.path
filename=input("Enter name of input file >")
infile=open(filename,"r")
and so on. It worked at school.
Now I came home and downloaded the file again but this time the same python program that worked in school does not recognizes color.txt
My teacher told the class to try
import os.path
if os.path.isfile("color.txt"):
print("color.txt")
to see if it exist but apparently it doesn't.
To clarify both times I downloaded the file to the desktop. At my school we use linux. At home I have windows. At home when you open the file it opens with notepad. In school it open with something else..I forgot. Please help.
Upvotes: 0
Views: 17740
Reputation: 42450
For your program to find the file color.txt
, your file needs to be in the same directory the program is executed from. If you downloaded the file to your desktop, and your program is executed from another directory, it won't find the file.
Alternatively, when you enter the name of the file, enter the entire absolute path. For a file on your desktop, that should be something like C:\Users\username\Desktop\color.txt
Upvotes: 1