【发布时间】:2013-08-15 00:19:58
【问题描述】:
我正在尝试从 CSV 文件构建 python 列表。我的 CSV 文件有 5 列,如下所示,用竖线 (|) 分隔:
QTP|Install|C:\Cone_Automation\RunTest.vbs|Install|Sequence
QTP|Open |C:\Cone_Automation\RunTest.vbs|Open |Sequence
QTP|Install|C:\Cone_Automation\RunTest.vbs|Install|Parallel
QTP|Install|C:\Cone_Automation\RunTest.vbs|Install|Parallel
QTP|Install|C:\Cone_Automation\RunTest.vbs|Install|Parallel
QTP|Open |C:\Cone_Automation\RunTest.vbs|Open |Sequence
QTP|Install|C:\Cone_Automation\RunTest.vbs|Install|Sequence
QTP|Open |C:\Cone_Automation\RunTest.vbs|Open |Parallel
QTP|Open |C:\Cone_Automation\RunTest.vbs|Open |Parallel
QTP|Open |C:\Cone_Automation\RunTest.vbs|Open |Parallel
以上是我的 CSV 测试用例。
我想根据文件的最后一列构建一个列表。
我想要一个列表,如果前两行在列 [4] 中有文本“序列”,那么我应该在列表 Seq1 中获得完整的行。
如果第 3、4 和 5 行有 Parallel,那么我应该在列表 Par1 中获得完整的第 3、第 4 和第 5 条记录。
然后,如果我在第 6 行和第 7 行有Sequence,那么我应该在Seq2 中获得列表。
之后,如果我将文本设为Parallel,那么我应该将列表设为Par2。
如何使用 Python 实现这一点?
【问题讨论】:
-
欢迎来到 Stackoverflow!到目前为止,您尝试过什么?