From ef93d4c5498dcf8957684e509559b1a107c1c30d Mon Sep 17 00:00:00 2001 From: Florent Lamiraux <florent@laas.fr> Date: Wed, 7 Dec 2011 17:37:06 +0100 Subject: [PATCH] Enforce compatibility with python3. Use PyObject_IsTrue to test a boolean in C/Python API, call print as a function. --- src/convert-dg-to-py.cc | 2 +- src/dynamic-graph-py.cc | 2 +- src/dynamic_graph/attrpath.py | 4 ++-- src/dynamic_graph/entity.py | 2 +- src/dynamic_graph/script_shortcuts.py | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/convert-dg-to-py.cc b/src/convert-dg-to-py.cc index a502b0e..6a6fe8e 100644 --- a/src/convert-dg-to-py.cc +++ b/src/convert-dg-to-py.cc @@ -73,7 +73,7 @@ namespace dynamicgraph { throw ExceptionPython(ExceptionPython::VALUE_PARSING, "bool"); } - bvalue = (pyObject == Py_True); + bvalue = PyObject_IsTrue(pyObject); return Value(bvalue); break; case (Value::UNSIGNED) : diff --git a/src/dynamic-graph-py.cc b/src/dynamic-graph-py.cc index aed5d53..0303fa7 100644 --- a/src/dynamic-graph-py.cc +++ b/src/dynamic-graph-py.cc @@ -114,7 +114,7 @@ namespace dynamicgraph { "second argument a filename."); return NULL; } - if (boolean == Py_True) { + if (PyObject_IsTrue(boolean)) { try { DebugTrace::openFile(filename); } catch (const std::exception& exc) { diff --git a/src/dynamic_graph/attrpath.py b/src/dynamic_graph/attrpath.py index d10778d..cdb6c7d 100644 --- a/src/dynamic_graph/attrpath.py +++ b/src/dynamic_graph/attrpath.py @@ -73,7 +73,7 @@ def setattrpath( target,path,attribute ): if callable(attribute): createCommandLauncher( pathk,path[-1],attribute ) else: - print "Should not happen" + print("Should not happen") setattr(pathk,path[-1],attribute ) def getattrpath( target,path ): @@ -100,7 +100,7 @@ def existattrpath( target,path ): pathk=target if type(path)==type(str()): path=path.split('.') for tokenk in path[0:-1]: - print 'check ',tokenk + print('check ',tokenk) privateName=tokenk+"_obj" if (privateName not in pathk.__dict__): return False diff --git a/src/dynamic_graph/entity.py b/src/dynamic_graph/entity.py index 7b140da..6d49da3 100644 --- a/src/dynamic_graph/entity.py +++ b/src/dynamic_graph/entity.py @@ -202,7 +202,7 @@ class Entity (object) : are not made with the class, but directly with the object instance. """ if (cmdName in self.__dict__) | (cmdName in self.__class__.__dict__): - print "Warning: command ",cmdName," will overwrite an object attribute." + print("Warning: command ",cmdName," will overwrite an object attribute.") docstring = wrap.entity_get_command_docstring(self.obj, cmdName) cmd = Entity.createCommandBind(cmdName,docstring) # Limitation (todo): does not handle for path attribute name (see setattrpath). diff --git a/src/dynamic_graph/script_shortcuts.py b/src/dynamic_graph/script_shortcuts.py index 099e974..deeddcf 100644 --- a/src/dynamic_graph/script_shortcuts.py +++ b/src/dynamic_graph/script_shortcuts.py @@ -53,11 +53,11 @@ def sigRepr( self ): def sigCall( sig,iter ): sig.recompute(iter) - print sigRepr(sig) + print(sigRepr(sig)) def sigTimeIncr( sig,iter ): sig.recompute(sig.time+iter) - print sigRepr(sig) + print(sigRepr(sig)) setattr(SignalBase,'__repr__',sigRepr) setattr(SignalBase,'__call__',sigCall) -- GitLab