不能在文件中写入超过204800个字符?

时间:2013-01-26 19:08:30

标签: python html file-io debian linuxmint

编辑2:对于那些想要仔细查看代码的人,这里是: https://github.com/pikzen/ffbookmark/blob/python-rewrite/ffbookmark.py

我在这里遇到了一些麻烦:每当我尝试将超过204800个字符写入文件时,python就会抛出一个IOError。我尝试了另一台计算机,并以768k字符崩溃。这是一个python问题,操作系统限制了什么?以下是我使用的代码:

with open('out.json', 'w') as f:
    json.dump(items, f)

items是一个简单的字典。我是从包含大约800个元素的HTML文件构建它。每个元素都是这样构建的:

bookmark = {}
            bookmark["title"] = link.contents[0]
            bookmark["id"] = id
            bookmark["parent"] = 5
            bookmark["dateAdded"] = 1
            bookmark["lastModified"] = 1
            bookmark["type"] = "text/x-moz-place"
            uri = link.get('href')
            # Shaarli's self links are totally messed up : ?xGRpkrp
            # But we can't simply oust links containing '?'s, because
            # php uses it, and pretty much everything does
            # however, if there's not dot, we can assume it's a 
            # Shaarli link.
            # If it's not, well too bad, false positive.
            if "?" in uri and not '.' in uri:
                bookmark['uri'] = "about:blank"
            else:
                bookmark['uri'] = uri
            id += 1

            try:
                # This line messes up when the end of the file has been reached
                # Rather than coding properly, let's just catch the exception
                desc = link.parent.next_sibling.next_sibling
                if desc and desc.name == "dd":
                    bookmark["annos"] = []
                    annos = {}
                    annos["name"] = "bookmarkProperties/description"
                    annos["flags"] = 0
                    annos["expires"] = 4
                    annos["mimeType"] = ""
                    annos["type"] = 3
                    annos["value"] = desc.contents[0]
                    bookmark["annos"].append(annos)

输出:

IOError (Errno 27) : File too large

编辑:附加信息: Python信息:

$ python --version
Python 2.7.3

使用的操作系统:

Linux Mint 13:限制:204.8kB

Debian 6.0:限制:768kB

1 个答案:

答案 0 :(得分:2)

这不是Python错误,而是您正在编写的文件系统的限制,或操作系统的等效(人为)限制。

使用ulimit -f检查文件大小限制。应该说unlimited。如果没有,您很可能想要编辑/etc/security/limits.conf。您可以使用以下命令搜索有问题的配置:

grep fsize /etc/security/limits.conf /etc/security/limits.d/ -r

您可能还想检查filesystem quota或grsecurity限制。

最后,您可能需要检查mount以确保您希望安装的文件系统是您看到的文件系统。