-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv_reader.py
More file actions
35 lines (27 loc) · 835 Bytes
/
csv_reader.py
File metadata and controls
35 lines (27 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import csv
import os
def read_csv_file(file_path):
"""Read and display the contents of a CSV file."""
if not os.path.exists(file_path):
print(f"File {file_path} does not exist.")
return
print(f"\nContents of {file_path}:")
print("-" * 50)
with open(file_path, newline='', encoding='utf-8') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
print(", ".join(row))
def main():
print("Reading CSV files in the data directory...")
# Define the CSV files to read
csv_files = [
"data/users.csv",
"data/sales.csv",
"data/employees.csv"
]
# Read each CSV file
for file in csv_files:
read_csv_file(file)
print("\nCSV files loaded successfully!")
if __name__ == "__main__":
main()