reading a CSV files columns directly into variables names with python

前端 未结 6 2033
梦毁少年i
梦毁少年i 2021-02-06 12:57

I want to read a CSV file\'s columns directly into variables. The result should be something like you would get with the following shell line: while IFS=, read ColumnName1

6条回答
  •  感情败类
    2021-02-06 13:44

    Thank you all for working with my question. Here is what I ended up doing. Simple, but it worked. Again, problem was to read a headless CSV into variables so that I could "do stuff"

    import sys
    
    for record in sys.stdin.readlines():
        record = record.rstrip()
        ColumnName1, ColumnName2, ColumnName2 = record.split(',')
    

    This does the same thing as the shell code I posted in the question: while IFS=, read ColumnName1 ColumnName2 ColumnName3 do stuff

    Thanks for all the help. I will be asking more questions soon!!

提交回复
热议问题