Anyone know of a simple library or function to parse a csv encoded string and turn it into an array or dictionary?
I don’t think I want the built in csv module because in all the examples I’ve seen that takes filepaths, not strings.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can convert a string to a file object using
io.StringIOand then pass that to thecsvmodule:simpler version with
split()on newlines:Or you can simply
split()this string into lines using\nas separator, and thensplit()each line into values, but this way you must be aware of quoting, so usingcsvmodule is preferred.On Python 2 you have to import
StringIOasinstead.