You can't call an instance method on the class itself; you have to create an instance, then call the method on that instance:
>>> connect2 = TamAccConnect2()
>>> connect2.func1()
You're going to have a similar, but opposite, problem when you try to call that other method, ReadCurrentData
. Because you didn't give it a self
parameter, when you try to call it on an instance, you'll get a TypeError
about too many arguments, instead of too few. (Also, it looks like you might have been expecting ReadCurrentData
to update a class, instance, or global variable, instead of just creating a local variable that goes away as soon as the method is done.)
While we're at it, if this is Python 2.x, you should always define new-style classes by explicitly inheriting from object
—e.g., class TamAccConnect2(object):
.
It's hard to explain all of this better in an SO answer than in a tutorial, so please re-read the official tutorial's section on Classes, or whichever other tutorial or text you're learning from.
If you've created other classes in a similar manner, they weren't fine. You may have gotten away with things because of other errors that cancelled this one out (e.g., you passed an argument when you shouldn't have, and the method never used its self
, or used it in such a way that it happened to work with the argument you passed), but it isn't actually working as intended.
If you're wondering exactly why the error message looks like this, it's a bit complicated. I've tried to write a gentle explanation here, but I suspect it's still hard to understand. Anyway, the short version is that you are not passing an argument to match the self
parameter, and you're not calling a bound method which would automatically pass the object it's bound to as an argument to match the self
parameter, so you get an error saying you're missing the self
argument.