I have a .csv file I am trying to read, but I'm having trouble. Please forgive me as this is a very remedial question:
I'm trying to read a file line-by-line with the following:
with open('Book8.csv') as fp:
for line in fp:
print line
If I do this I print the whole file. like so:
1,2,3
4,5,6
7,8,9
However I only want to print the middle line so I put
with open('Book8.csv') as fp:
for line in fp:
print line[1]
This gives me
� , , as my output.
I want the output to be 4,5,6. It seems the commas or the [1] character in each line is being treated as part of the line. I'm not sure how to fix this.
Eventually I'm going to want to do a regular expression on each of these lines to search for multiple substrings in each line.
For example:
Line 1: There is text I want in here that text is _:E28, _:K31 blah blah
Line 2: There is text I want in here that text is _:H27, _:K12 blah blah
Will it be possible to write a regex to create a list for each line containing only my text of interest?
For example: List 1=[":E28", ":K31"] List 2=["_:H27", "_K12"]