How can I access “static” class variables within methods in Python?
If I have the following code:
If I have the following code:
I know that python has a len() function that is used to determine the size of a string, but I was wondering why it’s not a method of the string object.
I have a python object with several attributes and methods. I want to iterate over object attributes. class my_python_obj(object): attr1='a' attr2='b' attr3='c' def method1(self, etc, etc): #Statements I want to generate a dictionary containing all of the objects attributes and their current values, but I want to do it in a dynamic way (so if … Read more
I saw this in someone’s code. What does it mean?
I do not fully understand classes. I have read the python documentation and several other tutorials. I get the basic gist of it but don’t understand the nuance. For instance in my code here:
I want to know the difference between __init__ and __call__ methods.
I’m doing Code Academy’s tutorials on Python, and I’m a bit confused about the definition of method and function. From the tutorial:
The code I have included below throws the following error: NameError: name 'Vector2' is not defined at this line: def Translate (self, pos: Vector2): Why does Python not recognize my Vector2 class in the Translate method? class Vector2: def __init__(self, x: float, y: float): self.x = x self.y = y def Translate(self, pos: Vector2): self.x … Read more
Consider this – a base class A, class B inheriting from A, class C inheriting from B. What is a generic way to call a parent class initialiser in an initialiser? If this still sounds too vague, here’s some code. class A(object): def __init__(self): print "Initialiser A was called" class B(A): def __init__(self): super(B,self).__init__() print … Read more
TypeError: Can’t instantiate abstract class B with abstract methods a