READ FILES using Python! (.txt, .json, .csv) 🔍

preview_player
Показать описание
# Python reading files (.txt, .json, .csv)

# ---------- .txt ----------

try:
with open(file_path, 'r') as file:
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

try:
with open(file_path, 'r') as 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

try:
with open(file_path, 'r') as 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")
Рекомендации по теме
Комментарии
Автор

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

# .txt

file_path =

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 =

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 =

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")

BroCodez
Автор

BROCODE IM A BIG BIG FAN, I learned Css and Html from you and am currently learning React.Js. BRO AM A BIG FAN THANKS ALLOT FOR TEACHING ME <3

Quizzes-nl
Автор

You can you use an 'r' in front of the absolute path and let the path unchanged. like this r"C:\User\HP\Descktop".

MarcsBianchini
Автор

yo I know you haven't done C videos in a while but could you please do a tutorial on preprocessor directives?? really need a good one right now and i can't find anything good online.

pizzalawl
Автор

Can you please make a video on Lambda Decorators in python... 🙏

robert-qnhy
Автор

Brooo i wanna see your C# window tutorial video

somonorhong
Автор

Came in clutch i have an exam on this tmr lol

DoomGuy_
Автор

When you will teach us the android development bro...♥♥♥♥♥♥♥♥

NazneenNaharNishi