Python Forum

Full Version: opening a file from a windows desktop folder- error opening file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Team,

I am trying to open a file that is available in the desktop folder with the below command but getting an error
that file is not present.

I don't have access to place the input file in the python folder to open the file.

code:
a=r'C:\Users\Charan\Desktop\Python\sample.txt'
b=open(a,'r')
error:
Error:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Charan\\Desktop\\Python\\sample.txt'
it looks OK and should work given the file exists. Sorry, but can you confirm one more time that file with that name exists at the this location?
(Dec-06-2018, 01:03 AM)Charan007 Wrote: [ -> ]a file that is available in the desktop folder
i.e. is the file on the Desktop or in a Python folder on the Desktop?