Closed SpheMakh closed 4 months ago
One of these how-can-this-be problems... the function is right there. How can it be invoking the dict comprehension and not invoking the function definition? Could you please add a "print(stringify)" statement just before the comprehension?
For some ungodly reason, this works
import sys, json
kwin = json.loads('{params_string}')
try:
utype = unicode
except NameError:
utype = bytes
kw = dict()
for key, val in kwin.items():
# stringify in a loop to avoid isue #300
if isinstance(val, (utype, str)):
x = str(val)
elif isinstance(val, list):
x = [stringify(y) for y in val]
else:
x = val
kw[key] = x
{command}(**kw)
I'll updated #298 accordingly
Oops! there's a big boo boo in the elif
clause. Having another go
"Ungodly" indeed! But if it works, who am I to complain...
It doesn't seem to like user-defined variables in nested structures. There's probably some blasphemous code in this this CASA module casa-6.4.1-12-pipeline-2022.2.0.68/lib/py/lib/python3.6/site-packages/casashell/private/init_system.py", line 238, in __evprop__ .1# exec(stmt)
(dare to look?)
Anyhoo, here is the updated and working Frankenstein monster
import sys, json
kwin = json.loads('{params_string}')
try:
utype = unicode
except NameError:
utype = bytes
kw = dict()
for key, val in kwin.items():
# stringify in a loop to avoid isue #300
if isinstance(val, (utype, str)):
x = str(val)
elif isinstance(val, list):
try:
x = list(map(lambda a: str(a) if isinstance(a, (unicode, str)) else a, val))
except NameError:
x = list(map(lambda a: str(a) if isinstance(a, (bytes, str)) else a, val))
else:
x = val
kw[key] = x
{command}(**kw)
Wrapping this up. Ended up using io.StringIO()
to read the parameter dictionary and encoding the contents as str
or bytes
as required by the python version.
Environment
casa-6.4.1-12-pipeline-2022.2.0.68
I get this error:
The error goes away if I pass the script as a file; see https://github.com/caracal-pipeline/stimela/blob/a2025c7f07ce6a2c4ece6fbabe2aadf93351a3d1/stimela/backends/flavours/casa.py#L73-L99