class

Call CURD operation of a class from another class

Call CURD operation of a class from another class Question: I have a class with create, update, and delete functions of Django CRUD Can I use the create, and update functions of first in another class create function from example : class A(viewsets.ModelViewSet): def create(self, request, *args, **kwargs): some code def update(self, request, *args, **kwargs): …

Total answers: 2

Why doesn't python support multiple constructors like Java?

Why doesn't python support multiple constructors like Java? Question: I know python isn’t Java—and I’m not trying to be biased towards Java or something. I barely even use Java. I know you can set a default value of a init parameter in python by doing something like: def __init__(name = "Quinn"): self.name = name but …

Total answers: 1

Simple problem with Class RandomEvent in Python

Simple problem with Class RandomEvent in Python Question: I create a simple text quest with random events, which accumulated a lot, and I decided to separate them into a separate class. But after that I got a problem. It doesn’t look complicated, but I can’t find a solution. import random class Hero: def __init__(self, name): …

Total answers: 1

Keyboard Commands in PyGame

Keyboard Commands in PyGame Question: I have made a test code to try and solve this problem. I cannot figure it out. The test code takes in keyboard commands 1,2,3 into pygame and prints out whichever key was pressed into the console. I wrote the code with classes and stuff because it will later go …

Total answers: 1

Python use instance of class in a function in another file

Python use instance of class in a function in another file Question: I have three files, app.py, server.py and tools.py the files are quite big in total, so i’ll just show excerpts server.py is basically just flask app.py looks about like this from server import Server from tools import Tools if __name__ == "__main__": web …

Total answers: 2

How to import class from a Python package directly

How to import class from a Python package directly Question: My current package looks something like this: package_repo/ package/ __init__.py module_one.py module_two.py tests/ setup.py Inside the module_one.py I have ClassOne,and inside the module_two.py I have ClassTwo. Now, if I want to import ClassOne into some other module, I write from package.module_one import ClassOne. Is it …

Total answers: 1

Python: Mutables in class states, what's going on under the hood?

Python: Mutables in class states, what's going on under the hood? Question: I’m currently doing an online course on OOP in Python and one of the skill tests was to write a password generator class. Below you’ll find the recommended answer. import re import random from string import ascii_letters, punctuation from copy import copy class …

Total answers: 3

Pandas dataframe showing ValueError with class

Pandas dataframe showing ValueError with class Question: I am trying to make a Dataframe inside a class called CaptainAmerica. I am trying to implement the values using the finalStats variable. I was expecting output until I ran into this error: raise ValueError("If using all scalar values, you must pass an index") ValueError: If using all …

Total answers: 1