Python: Create a list of tuples from file

后端 未结 2 1877
名媛妹妹
名媛妹妹 2021-01-17 05:57

I have a test file that I would like to load the create a list of tuples using the data on the file. The data on the file is as follows> how would I successfully load the fi

2条回答
  •  悲哀的现实
    2021-01-17 06:01

    A very straightforward way would be to use the csv module. E.g.:

    import csv
    
    filename = "input.csv"
    
    with open(filename, 'r') as csvfile:
        reader = csv.reader(csvfile, delimiter=',')
        for row in reader:
            print(row)
    

提交回复
热议问题