low-level csv

Dave Cinege dave at cinege.com
Sun Nov 17 15:30:07 EST 2019


The few times I looked at CSV module it never looked useful to me. I 
seem to use shlex for everything. For example:

def csv_split (s):
	lex = shlex.shlex(s, posix=True)
	lex.whitespace_split = True
	lex.whitespace = ','
	return list(lex)

will split on commas while honoring quoted values (and stripping out the 
quotes)

Dave


On 2019/11/17 08:18, Antoon Pardon wrote:
> This is python 2.6->2.7 and 3.5->3.7
> 
> I need to convert a string that is a csv line to a list and vice versa.
> I thought to find functions doing this in the csv module but that doesn't
> seem to be the case.
> 
> I can of course write special classes that would allow for this using
> a csv.reader and csv.writer but that would be some convoluted code.
> 
> Anyone some suggestions?
> 


More information about the Python-list mailing list