Skip to content

Instantly share code, notes, and snippets.

@kshirsagarsiddharth
Created August 7, 2020 07:20
Show Gist options
  • Select an option

  • Save kshirsagarsiddharth/f2f175fef23f27feba68d1871a27a511 to your computer and use it in GitHub Desktop.

Select an option

Save kshirsagarsiddharth/f2f175fef23f27feba68d1871a27a511 to your computer and use it in GitHub Desktop.
importance of newline = "" in writing the csv file
# opening a file without newline = ""
import csv
with open('something.csv','w') as f:
writer = csv.writer(f)
writer.writerow(["one", "two", "three"])
writer.writerow(["one", "two", "three"])
# as I am writing on windows system it uses "\r\n" line endings on write
# so an extra \r (carriage return) is added
with open('something.csv','r') as f:
reader = csv.reader(f)
for row in reader:
print(row)
"""
['SN', 'Movie', 'Protagonist']
[]
['SN', 'Movie', 'Protagonist']
[]
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment