Skip to content
Advertisement

Tag: oop

Can I improve this code to a more oriented OOP paradigm?

I am improving this code to a student, here is the image: So I rewrite this using list compreenssion and oriented to a formal class, so the second question is: Can I improve yet more this code? Answer Yes you can improve your code to be more “Object Oriented”. It doesn’t make sence that Aluno contains a list, Aluno should

Dynamically created classes with the same name

I’m trying to dynamically create subclasses in Python with type: and here’s what I see in the output: Obviously, this was not my intention. Two questions in that respect: How does Python handles multiple classes with identical names? What is a pythonic way to handle it? Of course, I can look up the name in the already existing subclasses, but

how to apply a class function to replace NaN for mean within a subset of pandas df columns?

The class is composed of a set of attributes and functions including: Attributes: df : a pandas dataframe. numerical_feature_names: df columns with a numeric value. label_column_names: df string columns to be grouped. Functions: mean(nums): takes a list of numbers as input and returns the mean fill_na(df, numerical_feature_names, label_columns): takes class attributes as inputs and returns a transformed df. And here’s

How to trigger a method in 2 instances of the same class object in Python?

I had 2 instances (st0, st1) of the same class (State) in which has 2 methods. Somehow when st0.loc_st() is called, I want that st1.rem_st() to be automatically triggered. How can I achieve that purpose with Python OOP? Sorry the code looks a bit naive, but it’s a simplified model saves the reading effort. Answer If you want the method

how to pass variables to method

I want to pass variables to the method. which of the following is better? (x and y are constants) or: Answer I’d argue the second one is better with regards to function purity, though this is a principle of Functional Programming rather than Object Oriented Programming. The only thing I’d wonder then is why you’d even make it a member

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

Advertisement