1. Files

archivo = open("numeros.txt", "w")
for numero in range(1, 31):
    archivo.write("%d\n" % numero)
archivo.close()

System Message: ERROR/3 (/home/runner/work/PyZombis/PyZombis/_sources/lectures/TWP23/TWP23_1_en.rst, line 22)

Duplicate ID – see lectures/TWP23/TWP23_1, line 26

.. datafile:: numeros.txt
    :cols: 20
    :rows: 10
    :edit:

Try the previous program:

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

1.1. Pythonic way

with open("numeros.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