Last active
February 5, 2019 10:16
-
-
Save Robofied/9b1ac37094f09b75d185b41ca6ffbd73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
with open('student_details.csv' , 'r') as csv_file1: | |
file1 = csv.reader(csv_file1) | |
## It will print the csv reader object. | |
print(file1) | |
## It will print each line as a list | |
for line in file1: | |
print(line) | |
#[Output]: | |
#<_csv.reader object at 0x000002D96F31BBA8> | |
#['Name ', 'Roll no.', 'Class '] | |
#['Akshay', '1', '2'] | |
#['Rajesh', '24', '3'] | |
#['Bram', '12', '6'] | |
#['Srishika', '45', '7'] | |
#['Radhika', '78', '6'] | |
#['Bluenix', '67', '6'] | |
## If you wants to remove the first line, ie., header part | |
with open('student_details.csv' , 'r') as csv_file1: | |
file1 = csv.reader(csv_file1) | |
## It will print the csv reader object. | |
print(file1) | |
## It will start pointing to second line as it is working as a generator. next(file1) | |
## It will print each line as a list | |
for line in file1: | |
print(line) | |
#[Output]: | |
#<_csv.reader object at 0x000002D96F31BC10> | |
#['Akshay', '1', '2'] | |
#['Rajesh', '24', '3'] | |
#['Bram', '12', '6'] | |
#['Srishika', '45', '7'] | |
#['Radhika', '78', '6'] | |
#['Bluenix', '67', '6'] | |
## delimiter is also a parameter in function reader sometimes, "," is not a separtor then we need to mention. | |
with open('student_details.csv' , 'r') as csv_file1: | |
file1 = csv.reader(csv_file1, delimiter =",") | |
## It will print the csv reader object. | |
print(file1) | |
## It will start pointing to second line as it is working as a generator. next(file1) | |
## It will print each line as a list | |
for line in file1: | |
print(line) | |
#[Output]: | |
#<_csv.reader object at 0x000002D96F31BD48> | |
#['Akshay', '1', '2'] | |
#['Rajesh', '24', '3'] | |
#['Bram', '12', '6'] | |
#['Srishika', '45', '7'] | |
#['Radhika', '78', '6'] | |
#['Bluenix', '67', '6'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment