Answer the question
In order to leave comments, you need to log in
YAML: Python vs PHP?
Good afternoon. There is a yaml file. In php use yaml_parse_file to convert it to an array. Well, it seems to work well. Then, for the sake of interest, I decided to see how it looks in Python. Installed PyYAML .
import yaml
stream = open("example.yaml", 'r')
print yaml.load(stream)
Answer the question
In order to leave comments, you need to log in
yaml_parse_file is implemented in C, that is, there is nothing faster. But PyYAML is written in python. Try to parse in php using the symfony/yaml package - there will be approximately the same result (only disable the Peklov yaml module before that).
PyYAML also seems to have C modules. There is an example here: pyyaml.org/wiki/PyYAMLDocumentation
I think in your case it will look like this:
from yaml import load, dump
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
with open('example.yaml', 'r') as stream:
data = load(stream, Loader=Loader)
output = dump(data, Dumper=Dumper)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question