From 8dff25296b16f903b18f2db12bd4341cbacb227b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 20 Jun 2025 14:42:52 -0400 Subject: [PATCH] restore pylammps.py --- python/lammps/pylammps.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/python/lammps/pylammps.py b/python/lammps/pylammps.py index 22e47d21fb..243ebc11bc 100644 --- a/python/lammps/pylammps.py +++ b/python/lammps/pylammps.py @@ -16,6 +16,10 @@ # Written by Richard Berger ################################################################################ +# for python2/3 compatibility + +from __future__ import print_function + import io import os import re @@ -758,7 +762,7 @@ class PyLammps(object): if self.comm_me > 0: raise Exception("PyLammps.eval() may only be used on MPI rank 0") - value = print('"$(%s)"' % expr).strip() + value = self.lmp_print('"$(%s)"' % expr).strip() try: return float(value) except ValueError: @@ -843,6 +847,10 @@ class PyLammps(object): elements.append(element) return elements + def lmp_print(self, s): + """ needed for Python2 compatibility, since print is a reserved keyword """ + return self.__getattr__("print")(s) + def __dir__(self): return sorted(set(['angle_coeff', 'angle_style', 'atom_modify', 'atom_style', 'atom_style', 'bond_coeff', 'bond_style', 'boundary', 'change_box', 'communicate', 'compute',