Skip to content

Commit a2579ba

Browse files
Diamond Bishopejguan
Diamond Bishop
authored andcommitted
fix newline windows issue in generate_csv (#675)
Summary: Fixes #674 ### Changes updated tutorial in documentation to specify the newline explitly `writer = csv.DictWriter(open(f"sample_data{file_label}.csv", "w", newline=''), fieldnames=fieldnames)` instead of: `writer = csv.DictWriter(open(f"sample_data{file_label}.csv", "w"), fieldnames=fieldnames)` ## Testing - tested by running the generate_csv function before and after on a windows machine, before was creating newlines between lines and throwing errors, after the created files don't have newlines and full tutorial works Pull Request resolved: #675 Reviewed By: ejguan Differential Revision: D38116301 Pulled By: NivekT fbshipit-source-id: 1885c40cdc739ca70c5236e983389d88f662b2d4
1 parent 553bd25 commit a2579ba

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

docs/source/tutorial.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ For this example, we will first have a helper function that generates some CSV f
7373
7474
def generate_csv(file_label, num_rows: int = 5000, num_features: int = 20) -> None:
7575
fieldnames = ['label'] + [f'c{i}' for i in range(num_features)]
76-
writer = csv.DictWriter(open(f"sample_data{file_label}.csv", "w"), fieldnames=fieldnames)
76+
writer = csv.DictWriter(open(f"sample_data{file_label}.csv", "w", newline=''), fieldnames=fieldnames)
7777
writer.writeheader()
7878
for i in range(num_rows):
7979
row_data = {col: random.random() for col in fieldnames}

0 commit comments

Comments
 (0)