2016-03-08 285 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]) 
...