首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python 关于资料读写

2013-01-20 
python 关于文件读写txt文本数据格式:12 2313 23...我想把每个元素放入set中,怎么老不行。。linesfile_rela

python 关于文件读写
txt文本数据格式:
12 23
13 23
...
我想把每个元素放入set中,怎么老不行。。
lines=file_relationships_of_sample_twice.readlines()
    while(''!=lines):
        nodeSet.update([lines[0],lines[1]])
        lines=file_relationships_of_sample_twice.readlines()

求教!
[解决办法]

nodeSet = set()

file_relationships_of_sample_twice = open( "1.txt" )

for line in file_relationships_of_sample_twice :
lst = line.split()
nodeSet.update( [lst[0], lst[1]] )

print nodeSet

如果题意理解错误,请告诉我。

热点排行