A question about python classes.
class test: def func1 (self): print ("Hello") def func2 (self): func1 () print (", world") test = test () test.func2 ()
In this code, when I try to call func1 with func2, I get an undefined error. How can I use it?
Sorry for the beginner's question.
Answer # 1
If you want to access your own member method, be sure to add self anywhere.
def func2 (self): # Add self. self.func1 () print (", world")
It is OK if you modify it like this.
Answer # 2
class Test: def func1 (self): print ("Hello") def func2 (self): self.func1 () print (", world") test = Test () test.func2 ()
This is why self is essential for the first argument.
- how to call another method in the same class from a method in a python class
- java - to create a method and call it from another class
- graph display method in python (matplotlib, seaborn) whether data frame transformation is necessary, etc
- vba - to end the original sub with the method created in the class module
- i want to share a class between parallel processes of python 384
- python - i want to display the variables defined in the class that inherits createview in createhtml
- python 3x - i want to run another python script from a python script
- java - method using graphics class created in another file cannot be used in main method of main class
- python - how to get data from model class by specifying specific value from query set
- i want to get new comments one after another with python scraping what is the quickest way to do this?
- python class, takes no arguments
- python number aggregation method csv
- behavior of class object in python
- python 3x - i use the count method but it doesn't display properly
- about import from another directory in python
- python - tkinter key input standby method
- please tell me the processing method other than exit() when the process is terminated prematurely with the conditional branch of
- image classification method using python
- python stepping method on vscode
- python - how to remove a list from a tuple and store only the value
- http error 503: service unavailable when doing amazon scraping with python
- python - i want to simplify the program that sequentially retrieves from the list
- python - regarding the problem that tries to decompose a string apostrophe using a dictionary but fails
- python - common behavior for everything in django
- python - i want to split one array into two without duplication
- about the problem that float subtraction does not work in numerical calculation in python
- python - something went wrong in the jupiter lab
- python - how to deal with error when converting pandas datetime type
- i want to read python time series data while shifting by 1 day