Pyrate here with a crash course on classes in Python!
A class is sort of like a blueprint. It's used to make objects starting with a certain amount of attributes(variables within an object) and a certain set of methods(functions within an object).
To make a class, you use:
class Testclass:
followed by the __init__ method(which gets ran as soon as you use the class to make an object):
def __init__(self, x, y):
Here, 'self' is, well, the object itself, and 'x' and 'y' are the parameters used in object creation. Before we move on, I'd just like to show how the parameters work when you create an object:
testobject = Testclass(1, 2)
So when you put in the parameters to make an object, you're entering the parameters for the __init__ function. Note that the 'self' attribute is ignored, so you only need to fill in the parameters after it. This goes for all methods within a class. Now, back to the __init__ method...
self.x = x
self.y = y
Here the attributes are assigned, and you can use them by entering something like 'testobject.y'.
Now, methods. They're functions you create within a class, and are made just like you would otherwise, but usually you include the object itself with it, by entering 'self' as an attribute:
def testmethod(self):
print self.x + self.y
And you use the method by entering:
testobject.testmethod()
That covers most of the class-related things. However, it doesn't end once you've written the class. You can assign methods and variables after you've made the object:
testobject.z = 13
testobject.secondtestmethod = examplefunction
Or you can even assign new methods and edit the class!
Testclass.__init__ = newinit
Testclass.thirdtestmethod = anotherfunction
But what if, say, you put an object within an object? Then you access them like you would with any other attribute, and then do what you'd normally do:
print testobject.lowertestobject.x
There. That should cover what is to cover on classes. Hope I didn't cram the info too tightly.
As for assigning strings as variable names... doesn't work, and you don't need it. Just make the class have a 'name' attribute.