Read files using Python! 🔍

Publicado el: 13 julio 2024
en el canal de: Bro Code
30,197
735

Python reading files (.txt, .json, .csv)

--------- .txt ---------

file_path = "C:/Users/HP/Desktop/input.txt"

try:
with open(file_path, 'r') as file:
content = file.read()
print(content)
except FileNotFoundError:
print("That file was not found")
except PermissionError:
print("You do not have permission to read that file")

--------- .json ---------
import json

file_path = "C:/Users/HP/Desktop/input.json"

try:
with open(file_path, 'r') as file:
content = json.load(file)
print(content )
except FileNotFoundError:
print("That file was not found")
except PermissionError:
print("You do not have permission to read that file")

--------- .csv ---------
import csv

file_path = "C:/Users/HP/Desktop/input.csv"

try:
with open(file_path, 'r') as file:
content = csv.reader(file)
for line in content:
print(line)
except FileNotFoundError:
print("That file was not found")
except PermissionError:
print("You do not have permission to read that file")


En esta página del sitio puede ver el video en línea Read files using Python! 🔍 de Duración hora minuto segunda en buena calidad , que subió el usuario Bro Code 13 julio 2024, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 30,197 veces y le gustó 735 a los espectadores. Disfruta viendo!