# 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")
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.
# 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")
You can you use an 'r' in front of the absolute path and let the path unchanged. like this r"C:\User\HP\Descktop".
Thank you.
Very helpful. Thanks, Bro!
Thanks a lot man, it helped me.
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
same here bro!thank u bro code
Thank you Bro for beautiful content
BIG THANKS TO YOU
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.
kotlin full course please man !
Brooo i wanna see your C# window tutorial video
Came in clutch i have an exam on this tmr lol
Thanks Bro
Can you please make a video on Lambda Decorators in python... 🙏
When you will teach us the android development bro...♥♥♥♥♥♥♥♥
First