The builtin open
function makes the contents of a file available, meaning you can manipulate it with your code. If you don't want to print a line of it, you can do .readlines()
. If you don't want to print it you can do anything else you want with it like store it in a variable.
One last note about file context:
with open("filename.txt", "r") as file:
for line in file:
# Do something with line here
This pattern is guaranteed to close, instead of calling open
and close
separately.
But if you wanted to open a text editor...
https://stackoverflow.com/a/6178200/10553976