IT/Python: Codecademy

12 File Input and Output and Finish course

Last72 2018. 3. 19. 22:30

write-only mode ("w")

read-only mode ("r")

read and write mode ("r+")

append mode ("a"), which adds any new data you write to the file to the end of the file.


my_file = open("output.txt", "r")

print my_file.read()

my_file.close()


my_file = open("text.txt", "r")

print my_file.readline()

print my_file.readline()

print my_file.readline()

my_file.close()


with open("text.txt", "w") as textfile:

  textfile.write("Success!")