Reputation: 73
I have code designed to take a file from a path I input at runtime. When I enter the path I expect to see the contents of the file but instead I'm met with the error No such file or directory
. After doing some googling I found a SO post here Python - input of file path but the accepted answer didn't apply. Why am I not getting my expected results?
note: I am using visual studios 2017 to run this.
My current source is:
def GetFile(input):
end_ = ""
data = open(input, 'r')
for line in data:
end_ = end_ + line
data.close()
return end_
dir = raw_input("Please enter the directory in which the file exists: ")
out = GetFile(dir)
print(out) #To see what was taken from the file
I have also tried using another function based off of suggestions in python docs as follows:
def GetFile2(input):
end2 = ""
with open(input,'r') as f:
end2 = f.read()
return end2
When I try either one, my result looks like:
I have also tried the following to no avail:
\
to /
Upvotes: 0
Views: 53
Reputation: 85767
Your Windows (or rather Explorer) is configured not to show file extensions. The actual name of your file is C:\Users\Semaphore\Desktop\test.txt.txt
.
Upvotes: 2