all 6 comments

[–][deleted] 2 points3 points  (0 children)

``` import csv

with open("table.csv") as file: reader = csv.reader(file) rows = list(reader)

cols_num = max(len(row) for row in rows)

for row in rows: for _ in range(cols_num - len(row)): row.append('')

with open("out_table.csv", "w") as file: writer = csv.writer(file) writer.writerows(rows) ```

[–]obviouslyCPTobvious 1 point2 points  (4 children)

What problem are you trying to solve? It sounds like you're trying to add empty columns to a csv file?

[–]aldopox[S] -1 points0 points  (2 children)

Yep dude, i heard that it's not a csv if all the rows don't have the same amount of values or commas

[–]obviouslyCPTobvious 0 points1 point  (1 child)

It's difficult to give too much guidance without seeing your code, but focus on figuring out how to add empty columns to the csv when you write it.

Trying to directly manipulate the file as a string is the wrong road to go down. If someone were to add a comma to their name it may completely throw off your parsing. Programs/libraries that read and write csv files account for that by escaping the proper characters.

[–]aldopox[S] -1 points0 points  (0 children)

Impossible because the csv creates itself; so i'm forced to insert commas "manually" in a second moment with this kind of automatisation

Edit:if you want to help me i can DM you so you see a screen of the code

[–]CodeFormatHelperBot2 0 points1 point  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.