Is there a way to open an excel sheet through python while being able to send this code to another computer and it opens on that computer as well? For example, I write the code to open the excel sheet and I email that code. How can I get it to open there as well? Or is there a way to open an excel file without having to use the path?
Asked
Active
Viewed 49 times
1 Answers
0
You can use csv module to open ".csv" data file (Comma split value)
to import csv, you can use this command
import csv
Example
import csv
with open('employee_birthday.txt') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
for row in csv_reader:
if line_count == 0:
print(f'Column names are {", ".join(row)}')
line_count += 1
else:
print(f'\t{row[0]} works in the {row[1]} department, and was born in {row[2]}.')
line_count += 1
print(f'Processed {line_count} lines.')
Output
Column names are name, department, birthday month
John Smith works in the Accounting department, and was born in November.
Erica Meyers works in the IT department, and was born in March.
Processed 3 lines.