# 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()
No comments:
Post a Comment