0

How can I use python to create and write to a text file in python, and also how would I be able to save this text file to my computer? I want this text file to accessible just by using Python, and everything in that text file to be accessible in the console.

I also want this file to be saved in the Documents directory.

The issue is that no output is given nor has any text file been created in the same destination.

This is the code I ran:

myfile = open("newfile.txt", "w")
myfile.write("This is text from newfile")
myfile.close()

2
  • Try to check this out: realpython.com/working-with-files-in-python Commented Oct 27, 2020 at 9:57
  • It's not clear. What do you mean by: "everything in that text file to be accessible in the console"? How does it relate to "saved in the Documents directory"? Commented Oct 28, 2020 at 1:52

1 Answer 1

-1

This code will create an file at the location of the .py

myfile = open("Greetings.txt", 'w')
myfile.write("Hello")
myfile.close()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.