methods

Python – Is there a method to calculate the signed area of a polygon?

Python – Is there a method to calculate the signed area of a polygon? Question: I have a polygon defined in a Python list with (x, y) coordinates. # for example polygon = [(0, 0), (2, 0), (2, 2), (1, 1), (0, 2)] I would like to get the signed area of this polygon. I …

Total answers: 1

How to check if certain class methods have been called from within the same class

How to check if certain class methods have been called from within the same class Question: I have some code that looks like this: class Template: def insert_text(self, text): # code goes here return def insert_photo(self, path_to_photo): # some more code goes here return def compose(self): # this composes/generates the text file based on the …

Total answers: 2

Multiple object returns from method not acting as expected

Multiple object returns from method not acting as expected Question: While playing around with pyautogui I decided to make a method to limit the position of my cursor depending on the size of my monitor, since I was moving my cursor randomy. This is what my first attempt looked like. max_x = 10 max_y = …

Total answers: 2

Why don't callable attributes of a class become methods?

Why don't callable attributes of a class become methods? Question: Consider the following snippet. import types def deff(s): print(f"deff called, {s=}") lam = lambda s: print(f"lam called, {s=}") class Clbl: def __call__(s): print(f"__call__ called, {s=}") clbl = Clbl() print(type(deff) == types.FunctionType) # True print(type(lam) == types.LambdaType) # True print(type(clbl) == Clbl) # True class A: …

Total answers: 1

python index [-1] shows wrong element

python index [-1] shows wrong element Question: As I learned, in python index -1 is the last number. for instant in: values = [1, 2 , 3, 4, 5, 6, 7, 8, 9, 10] print(value[-1]) returns 10 in output. Now, if I want to insert a number in the last position with insert method, I …

Total answers: 3

What is the type hint for a method?

What is the type hint for a method? Question: What is the right type hint for a method? There is typing.Callable, but I’m looking for a method type hint, and typing.Callable[[Self, …], …] is not working. I’ve tried this but it doesn’t work: class _Object: """An empty object for method type.""" def method(self) -> None: …

Total answers: 2

'>=' not supported between instances of 'method' and 'int'

'>=' not supported between instances of 'method' and 'int' Question: Here is the method causing the error: class Kilpailu(): def __init__(self, nimi, pituuskm, osallistujat): self.nimi = nimi self.pituuskm = pituuskm self.osallistujat = osallistujat def kilpailu_ohi(self): for i in self.osallistujat: if (i.getKuljettuMatka>=self.pituuskm): return True else: return False edit: here is also where getKuljettuMatka is defined class …

Total answers: 1