0

Hi I'm new on learning python and I'm learning python files handling. the following code works fine. But I can't find the folder where python creates this file. (I'm using Visual studio code )

f = open("demofile2.txt", "a") 
f.write("Now the file has new content ")
f.close()


f = open("demofile2.txt", "r") 
print(f.read())
Nahu
  • 59
  • 9
  • Have you checked inside the folder in which the python script runs? – matkv Feb 27 '20 at 21:13
  • "file is a path-like object giving the pathname (absolute or relative to the current working directory) " - You should always read the [docs for the code you're using](https://docs.python.org/3/library/functions.html#open) before posting. – Sayse Feb 27 '20 at 21:20

3 Answers3

0

the file your code created should be same location as your python code

Q.W.
  • 122
  • 1
  • 10
0

if you run this, you will know where the files are saved:

import os

print(os.getcwd())
Nicolas Gervais
  • 33,817
  • 13
  • 115
  • 143
0

An Interpreter, when you try to open or create a file via your code, will always be pointing to your Current/Present Working Directory.

Use the below line to know your pwd via your py file.

os.getcwd()

Via Terminal (OSX/Linux):

pwd

Via CMD (Windows):

cd
Ankith
  • 53
  • 5