Update Python Ofensivo

This commit is contained in:
2024-01-08 22:36:16 +01:00
parent d49859c627
commit 7c2ccb390c
2 changed files with 102 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
#!/usr/bin/env python3
"""
Pruebas con open de Python
w = write
r = read
a = append
b = binary
+ = read and write
"""
# Abrir fichero binario y guardarlo en otro
# imagen
with open("/home/v/Imatges/salvapantallas/peces.jpg", "rb") as f_in, open("image.png", "wb") as f_out:
file_content = f_in.read()
f_out.write(file_content)
# Antes
try:
with open("test.txt", "r") as f:
print(f.read())
except IOError:
print("\n[!] Error: No se ha podido abrir el fichero")
# Ahora
try:
with open("test.txt", "r") as f:
print(f.read())
except FileNotFoundError:
print("\n[!] Error: No se ha podido abrir el fichero")