python - 在 python 中读取 Freebase 数据转储,读取几行?

标签 python file readline freebase

我正在尝试使用 freebase 数据转储,但似乎我在使用 python 读取文件时遇到了一些问题。看起来我的程序无法读取所有行。

def test2():
    count=0
    for line in open(FREEBASE_TOPIC):
        count+=1
    return count

def test3():
    count=0
    for line in open(FREEBASE_QUAD):
        count+=1
    return count


if __name__ == "__main__":

   print "FREEBASE TOPIC - NR LINES:",test2()
   print "FREEBASE QUAD - NR LINES:",test3()

结果:

FREEBASE TOPIC - ITR TIME: 1.21000003815
FREEBASE TOPIC - NR LINES: 1643010

FREEBASE QUAD - ITER TIME: 0.797000169754
FREEBASE QUAD - NR LINES: 3155131

这可以是全部。它看起来只需要几行就可以包含整个 freebase。而且我看不出如何在 2 秒内迭代一个 33GB 的文件和另一个 5GB 的文件。

怎么了?我正在再次下载文件,以防下载过程中出现问题,但我的连接需要几十年的时间,所以我同时询问 ere。文件大小正确,我打印了一些行,它们看起来正确。

最佳答案

我遇到了一个问题:

open('file', 'rb')

应该可以解决。

chr(26)

有时会导致文件以默认文本模式“r”结尾。

关于python - 在 python 中读取 Freebase 数据转储,读取几行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10887001/

相关文章:

python - 将带有日期值的列表加载到 pandas 数据框中并随时间绘制事件图

php - 哪个函数更适合在 PHP : basename or pathinfo? 中检索文件的基本名称

shell - 编译 Readline 时对 "tputs"的 undefined reference

file - vim中当前工作目录的变量是什么?

asp-classic - ASP Readline 非标准行尾

c# - 一种压缩多个阅读线的方法?

python - 如何使用CYGWIN安装LAPACK和BLAS?

python - 用 python 抓取一些 ofx 数据

python - PyAudio - 多 channel 管理\去混音

c# - FreeSWITCH : Is there a way to get the audio stream from other leg via the native API