1. Files

archive = open("numbers.txt", "w")
for numbers in range(1, 31):
    archivo.write("%d\n" % numbers)
archive.close()
Data file: numbers.txt

Try the previous program:

You have already written to the file "numbers.txt". Now you are going to read the data you have written:

1.1. Pythonic way

with open("numbers.txt", "r") as f:
    print(f.read())
  • The previous code does the same as the Pythonic way.

  • In the previous slide we saw how normal programmers read

  • Python is great because you can always go deeper

  • Python is simple, but hard to exhaust

You have attempted of activities on this page