From b1e92c9ec6ea1487f951e0b8e1225f3d5ceef015 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 6 Apr 2022 17:38:25 -0400 Subject: [PATCH] update YAML reading python example to read faster using libyaml. --- doc/src/Howto_structured_data.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/src/Howto_structured_data.rst b/doc/src/Howto_structured_data.rst index 56a1778ece..f18fda4a8c 100644 --- a/doc/src/Howto_structured_data.rst +++ b/doc/src/Howto_structured_data.rst @@ -79,6 +79,10 @@ This data can be extracted and parsed from a log file using python with: .. code-block:: python import re, yaml + try: + from yaml import CSafeLoader as Loader, CSafeDumper as Dumper + except ImportError: + from yaml import SafeLoader, SafeDumper docs = "" with open("log.lammps") as f: @@ -86,7 +90,7 @@ This data can be extracted and parsed from a log file using python with: m = re.search(r"^(keywords:.*$|data:$|---$|\.\.\.$| - \[.*\]$)", line) if m: docs += m.group(0) + '\n' - thermo = list(yaml.load_all(docs, Loader=yaml.SafeLoader)) + thermo = list(yaml.load_all(docs, Loader=Loader)) print("Number of runs: ", len(thermo)) print(thermo[1]['keywords'][4], ' = ', thermo[1]['data'][2][4])