我正在制作一个脚本来提取cvs文件中的信息。 每列由“;”分隔。 输出应该是包含我想要提取的列的字符串列表。Python:全面列表中的别名
我想和全面的清单要做到这一点,我想这样做:
[ c[1] for c as l.split(";") in for l in lines ]
如果你知道Python中,你会猜测,这是行不通的。 我怎么能实现这样的事情?
当然,我可以使用[ l.split(";") for l in lines ]
但事实上,我需要提取几个列,因此做多个拆分不是正确的选择。
文件看起来像:
115239747;darwin;simone;[email protected];678954312
112658043;de beauvoir;charles;[email protected];745832259
115831259;ramanujan;godfrey;[email protected];666443810
114873956;hardy;srinivasa;[email protected];659332891
114823401;germain;marguerite;[email protected];768532870
115821145;yourcenar;sophie;[email protected];645388521
114560013;harendt;michel;[email protected];666458200
115702831;foucault;hannah;[email protected];691337456
,我想提取第二和第三列。
编辑:我不想只使用Python语言功能(无CVS库),因为它是一个关于Python的初学者课程。谢谢。
你把'''与'l'混合在一起。 – Forge
你比我快! ;) –
你的文件看起来像什么?预期的结果是什么? – styvane