Skip to content
Advertisement

Tag: class

How can I define name ‘unit’ in def to?

I am trying to create a temperature conversion module. My class is set up as below: I then try to convert using the following: The original prints work but the conversion has the error: NameError: name ‘unit’ is not defined. How can I avoid this? Answer

a simple way to produces classes with global state

Suppose I have a class, defined, for example, thus: Now, I want to create a class which is identical to testclass except I don’t want testclass’ state cl, but rather its own individual state. Experiment shows that inheriting from testclass inherits cl, so that does not work. Any words of wisdom appreciated. Does this require the whole metaclass machinery? (which

Why does a function in a class does not return anything?

For exercising reasons, I am trying to implement a class SSM which stands for Static Sorted Map in python in order to implement the methods min_value(self) : find the minimum value max_value(self) : find the maximum value search(self, key): to find an element in the list The list is assumed to be sorted. Here is the code for the class:

Wrong Implementation of LinkedList

I am having trouble with the following code segment. I can’t really figure out why it doesn’t work, any help is appreciated. It’s a very very simple mistake that I do not understand: Prints 5 and it keeps printing 5 if you write u.next.next.next.val, what I want is u.val = 5 , u.next.val = 1 and u.next.next = None Answer

unbind method from instance and bind to other instance

I have read this. is it possible to change: a1.show to a2.show, I mean, change the orientation of the method to point to different instance. I want to see 2 in console. I mean, for a normal method in class, change its instance, from a1 to a2? You may wonder why I do this, I have got a decorator to

Advertisement