Closed nesnoj closed 2 years ago
This looks like the wrong function call. Everything in the cli.py
is intended to be called via the command line interface (hence the name). They look like callable python functions, but the @-wrappers actually change how the function call works. What you want is what is inside the function, i.e.:
from omi.dialects import get_dialect
file_path = "in.json"
o = "out.json" # or None for printing
f = "oep-v1.4"
t = "oep-v1.4"
with open(file_path, "r") as infile:
from_dialect = get_dialect(f)()
obj = from_dialect.parse(infile.read())
to_dialect = get_dialect(t)()
s = to_dialect.compile_and_render(obj)
if o:
with open(o, "w") as outfile:
outfile.write(s)
else:
print(s)
Instead of loading the dialects dynamically (get_dialect(f)(), etc.), you can also use the respective dialect directly:
from_dialect = to_dialect = OEP_V_1_4_Dialect
Thanks @MGlauer, works like a charm :+1:
I expected OMI to work in Python using
translate()
, I triedbut it outputs
and exits Python. What's wrong here?