Showing posts with label 【PYTHON】Read and Write into text. Show all posts
Showing posts with label 【PYTHON】Read and Write into text. Show all posts

Wednesday, June 2, 2021

【PYTHON】Read and Write into text

 # create our text file to read

with open('textfile.txt', mode='w'as f:
      f.writelines(['This is a text file.\n''Now you can read it!'])
    # open a file and read the contents
file = open(file='textfile.txt', mode='r')
text = file.readlines()
print(text)  # remember if our last line is a variable, jupyter notebook will print out that variable
# the file is 'open' until we close it.
file.close()

[New post] All or Nothing

...