csv

[访问csv逗号分隔的文件]

csv读配置文件

        192.168.1.5,web # 配置文件按逗号分割
        list = csv.reader(file('a.csv'))
        for line in list:
            print line              #  ['192.168.1.5', 'web']

csv配合with读文件

        import csv
        with open('some.csv', 'rb') as f:
            reader = csv.reader(f)
            for row in reader:
                print row

csv配合with写文件

        import csv
        with open('some.csv', 'wb') as f:
            writer = csv.writer(f)
            writer.writerow(['Column1', 'Column2', 'Column3'])    # 写单行 列表
            writer.writerows([range(3) for i in range(5)])        # 写多行 列表套列表
文档更新时间: 2018-11-21 17:21   作者:RuM