Last active
February 5, 2019 10:25
-
-
Save Robofied/35f9400a82b126646a826c7507c55384 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
with open('student_details.csv' , 'r') as csv_file1: | |
## Reading csv file | |
file1 = csv.reader(csv_file1) | |
## Now we are creating new file to write a content. | |
## If this file doesn't exist already then it will create on its own. | |
## Opening in write mode. | |
with open('student_details2.csv' , 'w') as csv_file2: | |
## Using a 't' delimiter to store values. | |
file2 = csv.writer(csv_file2, delimiter='-') | |
## Reading line from file1 and then writing in a new created csv file. | |
for line in file1: | |
file2.writerow(line) | |
## Reading newly written file | |
with open('student_details2.csv' , 'r') as csv_file2: | |
## Reading csv file | |
## Here without delimiter specified | |
file2 = csv.reader(csv_file2) | |
## Output is different as it uses t as raw form. | |
for line in file2: | |
print(line) | |
#[Output]: | |
#['Name tRoll no.tClass '] | |
#['Akshayt1t2'] | |
#['Rajesht24t3'] | |
#['Bramt12t6'] | |
#['Srishikat45t7'] | |
#['Radhikat78t6'] | |
#['Bluenixt67t6'] | |
## See how with delimiter our output gets changed. | |
with open('student_details2.csv' , 'r') as csv_file2: | |
## Reading csv file | |
## Here without delimiter specified | |
file2 = csv.reader(csv_file2, delimiter="t") | |
## Output is different as it uses t as raw form. | |
for line in file2: | |
print(line) | |
#[Output]: | |
#['Name ', 'Roll no.', 'Class '] | |
#['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