是否有比标准.load方法更快的加载yaml文件的方法? Django的/ Python的

时间:2012-09-07 01:57:00

标签: python django upload load yaml

我正在加载一个大的yaml文件,它将永远消失。我想知道是否有比yaml.load()方法更快的方法。

我已经读过有一个CLoader方法但是无法运行它。

建议使用此CLoader方法的网站要求我这样做:

Download the source package PyYAML-3.08.tar.gz and unpack it. 
Go to the directory PyYAML-3.08 and run:
    $ python setup.py install


If you want to use LibYAML bindings, which are much faster than the pure Python version, you need to download and install LibYAML. 
Then you may build and install the bindings by executing
    $ python setup.py --with-libyaml install

In order to use LibYAML based parser and emitter, use the classes CParser and CEmitter:

    from yaml import load, dump
    try:
       from yaml import CLoader as Loader, CDumper as Dumper
    except ImportError:
       from yaml import Loader, Dumper

看起来这样可行但我在Django项目的任何地方都没有setup.py目录,因此无法安装/导入任何这些东西

任何人都可以帮我弄清楚如何做到这一点或让我知道另一种更快的加载方法吗?

感谢您的帮助!!

1 个答案:

答案 0 :(得分:-1)

我不知道什么更快 - bspymaster的想法可能是最有用的。

当您下载PyYAML-3.08.tar.gz时,在存档中会有一个setup.py可以运行的内容。

请注意使用LibYAML,请下载:http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz

使用http://pyyaml.org/wiki/LibYAML

中的说明运行

你需要一套构建工具,它应该安装在linux / unix上,因为osx确保安装了xcode,而且我不确定windows。