methods

decorator argument: unable to access instance attribute

decorator argument: unable to access instance attribute Question: Context class MyMockClient below has two methods: push_log: pushes one log from list self.logs and pops it push_event: pushes one event from list self.events and pops it Both methods are decorated using __iterate_pushes which essentially iterate push_event and push_log until their respective lists are entirely popped AND …

Total answers: 1

Is there any way to create a user generator?

Is there any way to create a user generator? Question: I need your help, I’m trying to create a program that can generate usernames by entering its first and lastname and apply some rules specifically, but I don’t know how to store a list of elements into a list on Python. print(‘Welcome to your program!’) …

Total answers: 1

How to fix? TypeError: argument of type 'PasswordManager' is not iterable

How to fix? TypeError: argument of type 'PasswordManager' is not iterable Question: I keep getting the following error and I can’t seem to find a solution for it. if password not in old_passwords: TypeError: argument of type ‘PasswordManager’ is not iterable For clarity, I needed to create a class called ‘PasswordManager’. The class should have …

Total answers: 2

What are the reasons for using type(obj).method() instead of obj.method()?

What are the reasons for using type(obj).method() instead of obj.method()? Question: I’ve seen a couple of times methods being called on the type of an object instead of the object itself. What might the reasons for that be, especially with special methods? Example from documentation: "For instance, if a class defines a method named _getitem_(), …

Total answers: 1

assigned lambda as method: self not passed?

assigned lambda as method: self not passed? Question: I want to create a method in a class object (depending on some condition). This works when I create the lambda in the class (m2) and when I assign an existing method to a class attribute (m3), but NOT when I assign a lambda to a class …

Total answers: 2

Add method to initialized object (python)

Add method to initialized object (python) Question: I want to add a method to an object that has already been instantiated. The object is an instance of type vaderSentiment.vaderSentiment.SentimentIntensityAnalyzer (Vader is a popular NLP model). In order to get the predicted negative tone of a text I need to do the following: # Import model …

Total answers: 1

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

'<=' not supported between instances of 'int' and 'method' Question: >! How to fix this error? I wanted to make this application in such a way that when you enter into Text_Field = Entry (root, textvariable = txt), e.g. the number 20, a 20-character password is generat ‘<=’ not supported between instances of ‘int’ and …

Total answers: 2

How do I create a function/method out of this code and then call it to the main()?

How do I create a function/method out of this code and then call it to the main()? Question: enter code hereThis is the original code that I wrote: while True: user_input = (input(">>",)) try: user_input = int(user_input) except ValueError: pass if user_input in range(1, len(something): break I want to put in a method: `get_user_answer(n: int, …

Total answers: 3