From 0262a54ecfeb809eb8bc3a09f9ae148a747669c8 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 15 Mar 2017 21:56:39 -0400 Subject: [PATCH] Fix Python 3 compatibility by encoding strings passed as c_char_p --- python/lammps.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/lammps.py b/python/lammps.py index 7344a16be3..80d1a87159 100644 --- a/python/lammps.py +++ b/python/lammps.py @@ -190,12 +190,15 @@ class lammps(object): # send a list of commands def commands_list(self,cmdlist): - args = (c_char_p * len(cmdlist))(*cmdlist) + cmds = [x.encode() for x in cmdlist if type(x) is str] + args = (c_char_p * len(cmdlist))(*cmds) self.lib.lammps_commands_list(self.lmp,len(cmdlist),args) # send a string of commands def commands_string(self,multicmd): + if type(multicmd) is str: + multicmd = multicmd.encode() self.lib.lammps_commands_string(self.lmp,c_char_p(multicmd)) # extract global info