Check out the documentation for the csv
module, which says:
reader(...) csv_reader = reader(iterable [, dialect='excel'] [optional keyword args]) for row in csv_reader: process(row) The "iterable" argument can be any object that returns a line of input for each iteration, such as a file object or a list. The optional "dialect" parameter is discussed below. The function also accepts optional keyword arguments which override settings provided by the dialect.
So, if you have a line:
>>> s = '"this is", "a test", "of the csv", "parser"'
And you want an “object that returns an input string for each iteration”, you can simply wrap your string in a list:
>>> r = csv.reader([s]) >>> list(r) [['this is', 'a test', 'of the csv parser']]
And how do you parse the string with the csv
module.
source share