Created
August 7, 2020 07:20
-
-
Save kshirsagarsiddharth/f2f175fef23f27feba68d1871a27a511 to your computer and use it in GitHub Desktop.
importance of newline = "" in writing the csv file
This file contains hidden or 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
| # 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