aboutsummaryrefslogtreecommitdiff
path: root/Python/pywarpx/Bucket.py
diff options
context:
space:
mode:
authorGravatar David Grote <grote1@llnl.gov> 2021-12-19 23:06:11 -0800
committerGravatar GitHub <noreply@github.com> 2021-12-19 23:06:11 -0800
commitb14130431bc17e2eee5e8d4677688793f240e74b (patch)
tree66dcca3fdb2a9a6a04c687a8a711332707913d5f /Python/pywarpx/Bucket.py
parenta194b909f73c44703b013b39dbcead0f278a8ba6 (diff)
downloadWarpX-b14130431bc17e2eee5e8d4677688793f240e74b.tar.gz
WarpX-b14130431bc17e2eee5e8d4677688793f240e74b.tar.zst
WarpX-b14130431bc17e2eee5e8d4677688793f240e74b.zip
For Python inputs, values with temporary variables are wrapped in quotes (#2690)
Diffstat (limited to '')
-rw-r--r--Python/pywarpx/Bucket.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/Python/pywarpx/Bucket.py b/Python/pywarpx/Bucket.py
index b4ae4a06a..3a0d2862c 100644
--- a/Python/pywarpx/Bucket.py
+++ b/Python/pywarpx/Bucket.py
@@ -50,20 +50,24 @@ class Bucket(object):
if value is None:
continue
# --- repr is applied to value so that for floats, all of the digits are included.
- # --- The strip is then needed when value is a string.
+ # --- The strip of "'" is then needed when value is a string.
if isinstance(value, str):
- rhs = value
+ if value.find('=') > -1:
+ # --- Expressions with temporary variables need to be inside quotes
+ rhs = f'"{value}"'
+ else:
+ rhs = value
elif np.iterable(value):
if len(value) == 0:
# --- Skip if empty
continue
# --- For lists, tuples, and arrays make a space delimited string of the values.
# --- The lambda is needed in case this is a list of strings.
- rhs = ' '.join(map(lambda s : repr(s).strip("'\""), value))
+ rhs = ' '.join(map(lambda s : repr(s).strip("'"), value))
elif isinstance(value, bool):
rhs = 1 if value else 0
else:
rhs = value
- attrstring = '{0}.{1} = {2}'.format(self.instancename, attr, repr(rhs).strip("'\""))
+ attrstring = '{0}.{1} = {2}'.format(self.instancename, attr, repr(rhs).strip("'"))
result += [attrstring]
return result