Classes in PYTHON vs JAVASCRIPT

Am studying the difference between those two languages and i was wondering why i can’t access the variables in javascript classes without initiating an instance but i can do that in python here is an example of what am talking about: PYTHON CLASS class Car: all =[] def __init__(self, name): self.name = name Car.all.append(self) def… Read More Classes in PYTHON vs JAVASCRIPT

Printing different values within class in Python

I’ve been trying to get the method to print out the specific attribute within class. Although I’ve already used _str_ for another thing, and for now it returns the location of my method, which is useless to me. class Account(): def __init__(self,name,value): self.name = name self.value = value def __str__(self): return f’Account owner: {self.name}\nAccount balance:… Read More Printing different values within class in Python

Printing lists with __str__ and __repr__ in Python

I have a class Player which puts created objects in a List: class Player: all = [] def __init__(self, name: str): self.name = name Player.all.append(self) def __repr__(self): return f"N: {self.name}" I wanted to print the list of the following objects using repr: player1 = Player("p1") player2 = Player("p2") player3 = Player("p3") print(Player.all) I got what… Read More Printing lists with __str__ and __repr__ in Python

TypeError in Python: "init() got an unexpected keyword argument 'fov'" when creating an instance of a Camera class

I’m working on a 3D rendering application in Python and encountered an issue when trying to create an instance of the Camera class. The error message I’m getting is: TypeError: Camera.__init__() got an unexpected keyword argument ‘fov’ Here’s the relevant code snippet: class Scene(): def __init__(self, ambient_color = vec3(0.01, 0.01, 0.01), n = vec3(1.0,1.0,1.0)) :… Read More TypeError in Python: "init() got an unexpected keyword argument 'fov'" when creating an instance of a Camera class

How would i have a class return a list, tuple or dictionary?

I want to have a class return a list, tuple or dictionary. And use it like a regular list class MyClass: def __init__(self, *args): for i in range(len(args)): args[i] += 1 def __some_dunder_method__(self): return self.args obj = MyClass(0, 1, 2, 3, 4, 4) print(obj[1]) # Wanted Output: 2 print(obj[2:5]) # Wanted Output: [3, 4, 5]… Read More How would i have a class return a list, tuple or dictionary?

I am new to python and i dont know why this code isnt working

class Car: def __init__(self, pos=0): self.pos = pos def move(self, direction): self.pos = self.pos + direction def get_position(self): return self.pos def main(): n = int(input()) car = Car() for _ in range(n): instruction = input() if instruction == "MOVE": distance = int(input()) car.move(distance) elif instruction == "POSITION": position = car.get_position() print(position) if __name__ == ‘__main__’:… Read More I am new to python and i dont know why this code isnt working

C++ bad function call

Im a beginner at c++, i followed some advice on using lambdas instead of a comparator class for my set. I have something like this: class Processor { private: const function<bool(std::string, std::string)> _lenComp = [](string a, string b) { return a != b && a.size() >= b.size(); }; set<string, decltype(_lenComp)> _inputSet; … public: Processor() :… Read More C++ bad function call