spam.txt
filewith open('spam.txt') as f:
contents = f.read()
print(contents)
NOTE: Using with
will automatically close the file when the function is done executing
help
command
help(f)
will provide information about the file provided by the file wrapperdir
command
print(dir(f))
will return information about commands able to execute on the filedir
shows the attributes of the file
spam.txt
filewith open('spam.txt') as f:
f.write('Do not like eggs')
with open('brain.jpeg', mode='rb') as f:
contents = f.read()
print(contents)
# Will print a string of bytes the refer to the jpeg