Skip to content
Advertisement

Tag: class

Creating a class property using a function

I found this fantasy name generator here. I am trying to adapt the code to suit my purpose. I want to create an NPC name automatically, using the function name_gen within the class NPC. With the NPC characteristics being: The code from the name generator I need is the following: Now the only thing I think I still need to

asdict() inside .format() in a Python class

How can I use asdict() method inside .format() in oder to unpack the class attributes. So that instead of this: I could write something like this: Answer asdict should be called on an instance of a class – self, in this case. Additionally, you don’t need the dict’s keys, you need its values, which you can spread using the *

Takes 1 positional argument but 2 were given Python Tkinter

I am working on one feature of my software which takes keyboard which I have bind to the window like this win.bind(‘<Key>’, self.triggerBackButton). And here is the callback funtion. Logic of above function goes something like this. It takes self and event as input, where event holds the information like from where it was triggered, which button triggered it etc.

assert menu.__str__() == “” AssertionError

I get assertion error when i try to assert “” (empty string) into str function. Could anyone enlighten me as of why that happens. Totally clueless here. I know the str function needs to return a string but as far as i know it is returning a string when i run: The error comes when i run: here is my

Advertisement