What is the right way to make a wrapper? (I'm a Python noob)

Official forum for open source FreePIE discussion and development.
Post Reply
TiagoTiago
One Eyed Hopeful
Posts: 33
Joined: Thu Mar 13, 2014 1:49 am

What is the right way to make a wrapper? (I'm a Python noob)

Post by TiagoTiago »

So i decided to make a wrapper for the hydra class to make it so i could always get the controller that is on the side i want without having to duplicate code everywhere to check sides each time. But i don't know enough about Python.

I tried doing this:

Code: Select all

class MHydra:
	"Sides aware Hydra wrapper"
	def L():
		if(hydra[0].side == "L"):
			return hydra[0]
		if(hydra[0].side == "R"):
			return hydra[1]
	def R():
		if(hydra[0].side == "L"):
			return hydra[0]
		if(hydra[0].side == "R"):
			return hydra[1]
I thought that would let me do things like MHydra.L.pitch, and get the pitch of the Left controller even if i swap the sides after the script started. But that doesn't work, the Error log thingy says "'instancemethod" object has no attribute 'pitch'".


So what is the right way to make a wrapper class?
Post Reply

Return to “FreePIE”