我是服务器管理员。我不用写太多脚本就可以溜走了,但唉,它已经抬起了它丑陋的头。
小结:我有示例.csv如下所示:
Stan,Marsh,Stan Marsh,1001,899,smarsh,smarsh@info.com
Eric,Cartman,Eric Cartman,1002,898,ecartman,ecartman@info.com
现在。我试着读入csv文件。然后,我想从每一行取一个值,然后把它放进类似这样的东西中
^{pr2}$如您所见,我正在尝试创建一个LDIF文件,它允许我导入用户名,然后自动填充变量。
我就是不能把这些东西拼在一起。
我也没走多远。我学会了打印行,耶!
import csv
with open('example.csv', 'rb') as f:
reader = csv.reader(f)
for row in reader:
print row
我认为逻辑如下。
任何帮助都将不胜感激。
这样的事情应该行得通。在
对于像你这样的文件来说,CSV模块是多余的。在
我在这里使用的一些Python习惯用法:
dict(zip(keys, values))
将键列表和值列表按拉链拉大;dict
函数(或dict.update
)可以将它们作为键-值对进行消化以添加到dict中%(foo)s
)可以消化dictdefaults
位就在那里,这样字符串插值就不会因丢失的值而窒息。适应你的需要。:)一。在
相关问题 更多 >
编程相关推荐