-2

[ VSCODE ] it's a simple code to read a text file, but it keeps giving me errno 13

with open('movie.txt') as file_object:
    content = file_object.read()
    print(content.strip())

the file is saved as movie.txt, but when i used that it said there was no file under that name, when I do in fact have it saved. when i changed changed to with open('movie'), without the .txt extension, it said permission error. I've searched everywhere but i cant find the solution.

UPDATE : works if i use absolute path.

  • 1
    where the hell is .txt extention of that file ? – ghost21blade Sep 17 '22 at 08:19
  • Hello - Welcome. Because of the vaguness of question I am going to assume you need to run vscode as admin if you are in windows. Permission error is usually permissions (as it sounds) or the file is currently locked/inuse. – PythonKiddieScripterX Sep 17 '22 at 08:26
  • 1
    You probably have a directory called *movie* in your current working directory. If you want to open movie.txt try using an absolute path – DarkKnight Sep 17 '22 at 08:26
  • Welcome to Stack Overflow. As you can see from the comments, the question is not really clear. Please read [ask] and try to improve your question so it's more on-topic here. – wovano Sep 17 '22 at 08:41
  • So it seemed like you had a simple path error which has now been solved. Is there still a question? Otherwise you might remove this question, since it does not seem to be useful for others, IMHO. – wovano Sep 21 '22 at 10:05

1 Answers1

-1

Your question is answered here. There is a directory named movie in your directory structure, which makes vscode open a directory instead of a file.

What you need to do is replace movie with movie.txt:

with open("movie.txt") as file_object:
    content = file_object.read()
    print(content.strip())
MingJie-MSFT
  • 5,569
  • 1
  • 2
  • 13