Python: Turn a comma-delimited string into a CSV -


i have long string in type of format [var1,var2,var3,...], [var1,var2,var3,...], ... (it's 1 giant string)

what best way turn large csv each [var1,var2,var3,...] existing row in csv each component var1, var2, var3, etc delimited 1 another? using python3 solve problem.

as long there's no malformed data might away this:

>>>import numpy np >>>import ast >>> s = '[1, 2, 3], [4,5,6], [7,8,9]'    # string >>> ll = np.vstack(ast.literal_eval(s))  # converts python >>> ll array([[1, 2, 3],        [4, 5, 6],        [7, 8, 9]]) 

writing list of lists csv can done pretty csv package.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -