0

I recently installed Anaconda, and am using it to run Idle.

I'm trying to figure out file I/O. I have a file created -

file = file.open('output.txt', 'w')

I wrote to the file like so -

file.write('test')

Idle spit out '4' (1 for each character, I'm guessing).

But I don't know where idle created the file. I checked the Anaconda folder, and I checked the idlelib folder in Anaconda, but there was no file 'output.txt' in either.

So where did Idle create the file? Or did it only create it in memory, and there's more I need to do to finalize and output the file?

Will
  • 3,413
  • 7
  • 50
  • 107
  • Files are typically created in the current directory. Make another small script with this code: `import os; print(os.getcwd())` and run it, to see what the current directory is. – John Gordon Mar 02 '23 at 05:03
  • 1
    "But I don't know where idle created the file." The same place that a command-line program would have: in the current working directory. Granted, the IDLE process might have a different CWD from what you expect. Anaconda is also irrelevant to the problem. – Karl Knechtel Mar 02 '23 at 05:06
  • Python creates the file *exactly where **you** tell it to* – juanpa.arrivillaga Mar 02 '23 at 06:31
  • @JohnGordon to be more specific, files are *always* created in the *path you give to the `open` function*. If that is a relative path, then that is *relative to the working directory*. If it is an absolute path, then the path is just the absolute path – juanpa.arrivillaga Mar 02 '23 at 20:53

0 Answers0