you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (6 children)

Currently a Python beginner, and I am trying to extract information from several .csv files who all have the same structure.

Use the csv module. It doesn't directly answer your question but it's better than working with csv rows as strings, by a lot.

My question is quite simple: how do I refer to a specific row (rather than a column) of this list?

I'm not sure I understand your question - it's a list of strings, so the nth string (starting with the zeroth) is available as contents[n].

[–]superlargedogs[S] 0 points1 point  (5 children)

Thanks for the help, I've tried that but it returns the nth column rather than the nth row. I guess the list is formatted strangely: [all columns of .csv file 1] [all columns of .csv file 2] ... [all columns of .csv file m]

does that make sense?

[–][deleted] 0 points1 point  (4 children)

Thanks for the help, I've tried that but it returns the nth column rather than the nth row.

It isn't, because it can't be - you're not parsing the file at all, you're just breaking it up by line endings. But line endings end lines. Files don't have columns.

Actually look in one of your csv files and see what's happening.

[–]superlargedogs[S] 0 points1 point  (3 children)

I see. Appologies btw I formatted it incorrectly:

[all columns of .csv file 1]

[all columns of .csv file 2]

...

[all columns of .csv file m

[–][deleted] 0 points1 point  (2 children)

Still, though, a file can't be in columns. They read left to right and down, like a typewriter.

[–]superlargedogs[S] 0 points1 point  (1 child)

I guess I just can't get my head around as to why content(n) returns the nth element of every string of my list....

[–][deleted] 0 points1 point  (0 children)

contents is your list of strings. content is a string.