将值与元组列表分开

时间:2014-08-25 08:37:14

标签: python

如何使用line.split(“,”)将每个值与元组列表分开?(python)

code > for line in path_list:
           val=line.split(",")
           print val

path_list[ (<__main__.wirelessnode instance at 0x19a2170>, <__main__.wirelessnode instance at 0x19a2290>, <__main__.wirelessnode instance at 0x19a04d0>, <__main__.wirelessnode instance at 0x19a1950>, <__main__.wirelessnode instance at 0x19a1320>, <__main__.wirelessnode instance at 0x19a24d0>)]

AttributeError:'tuple'对象没有属性'split'

1 个答案:

答案 0 :(得分:1)

path_list是元组列表。

list这样的tuple已经是&#34;项目序列&#34;。您可以使用for in

走路
for line in path:
    for val in line:
        print val

有关更多见解,请参阅documentation about basic Python data structures