Sunday, December 21, 2008

Useful python methods when working in boost (pyc++)

def printlist(x):
y = ""
for z in x:
y += str(z)
return y

Boost lists just show the memory address and are kinda useless. This just prints a list


def debugpickle(obj,tofind = Ogre.Vector3,depth = 0):
print obj
depth +=1
if depth > 10:
return
if isinstance(obj, tofind):
return obj
if hasattr(obj, "__getstate__"):

for x in obj.__getstate__().values():
debugpickle(x,tofind,depth)
elif hasattr(obj, "__dict__"):

for x in obj.__dict__.values():
debugpickle(x,tofind,depth)
elif hasattr(obj, "__iter__"):
for x in obj:
debugpickle(x, tofind,depth)

This could probably be done better, but it was all I needed, for a quick way of finding out what can't be saved in pickle

No comments:

Post a Comment