且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在不导入.csv模块/库的情况下从.csv文件加载数据

更新时间:2021-09-09 23:21:51

假设您在t.csv中有数据.您可以将数据保存在列表中,然后在文件的每一行上使用 分解>,然后将拆分结果附加到结果中.使用csv模块可以为您完成此操作,但是您可以使用 split 复制定界符行为.

Lets say you have the data in t.csv. You can hold the data in a results list, then use split on each line in the file and append the results of your split to results. Using the csv module would have done this for you, but you can replicate the delimiter behaviour with split.

with open('t.csv', 'r') as f:
    results = []
    for line in f:
            words = line.split(',')
            results.append((words[0], words[1:]))
    print results