Advertisement
teslariu

op

Jul 10th, 2021
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4.  
  5. """
  6. Resumen de help(open)
  7. ========================================================================
  8.  Character Meaning
  9.  ------------------------------------------------------------------------
  10.  'r'       open for reading (default)
  11.  'w'       open for writing, truncating the file first
  12.  'x'       create a new file and open it for writing
  13.  'a'       open for writing, appending to the end of the file if it exists
  14.  'b'       binary mode
  15.  't'       text mode (default)
  16.  '+'       open a disk file for updating (reading and writing)
  17.  'U'       universal newline mode (deprecated)
  18. ========================================================================
  19.  
  20. """
  21. # Creo un archivo y le guardo datos
  22. f = open("archivo.txt","x")
  23.  
  24. # Escribo en el archivo y lo cierro
  25. f.write("Hola mundo\n")
  26. f.close()
  27.  
  28. # Abro el archivo en modo lectura, imprimo los datos y lo cierro
  29. f = open("archivo.txt")
  30. print(f.read())
  31. f.close()
  32.  
  33. # Abro el archivo para agregarle una línea:
  34. f = open("archivo.txt","a")
  35. f.write("Chau mundo\n")
  36. f.close()
  37.  
  38.  
  39.  
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement