2016-03-08 286 views
0

如何在python中讀取和提取.vec文件中的數據?如何從python中的.vec文件讀取和提取數據

f = open("test.vec","r") # opens file with name of "test.txt" 
print(f.read()) 
f.close() 

但我不能提取信息。我希望數據將存儲在test.vec文件中的各個陣列中。

+0

您是否介意在數據文件中發佈** short **提取? – gboffi

回答

1
with open("file.txt", "r") as ins: 
    array = [] 
    for line in ins: 
     array.append(line) 

試試這個。這有點複雜。否則,試試這個簡單的。

with open('filename') as f: 
    lines = f.readlines() 
0

我想你可以從這個項目here得到一些啓發。您的重要部分開始於line 131,即

... 
with open(f, 'rb') as vecfile: 
    content = ''.join(str(line) for line in vecfile.readlines()) 
    val = struct.unpack('<iihh', content[:12]) 
...