Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Read files using Python! ๐Ÿ”
Play lesson

Python tutorial for beginners ๐Ÿ - Read files using Python! ๐Ÿ”

4.0 (0)
8 learners

What you'll learn

This course includes

  • 14.3 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

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

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere