[Python] No value for argument'self' in unbound method call

I'm new to Python. I couldn't understand the idea of self, and I stumbled on it so I made a note.

class HelloWorld:
    def __init__(self):
        self.message = 'Hello,World'
    def gree(self):
        print(self.message)
import hello

h = hello.HelloWorld
h.gree()

With this code, h.gree () gives the error "No value for argument'self' in unbound method call". The content of the error is that there is no argument self of the function gree

Isn't it necessary to specify self as an argument when calling a function? I stumbled.

Solved by making the code of sample.py below

import hello

h = hello.HelloWorld()
h.gree()

reference

h = hello.HelloWorld
print(type(h))
h = hello.HelloWorld()
print(type(h))
<class 'type'>
<class 'hello.HelloWorld'>

Substitute class definition for hello.HelloWorld assign an instance of the class with hello.HelloWorld ()

I understand that self does not work with hello.HelloWorld because it holds the instance information of the class.

Recommended Posts

[Python] No value for argument'self' in unbound method call
Simplex method (simplex method) in Python
Private method in python
[python] Method to darken RGB value in hexadecimal notation
Python code for k-means method in super simple case
Shapley value calculation in Python
Search for strings in Python
Techniques for sorting in Python
Implement method chain in Python
Dynamically call methods in Python
Suppressing method overrides in Python
About "for _ in range ():" in python
List method argument information for classes and modules in Python
How to use the __call__ method in a Python class
Newton's method in C ++, Python, Go (for understanding function objects)
Check for memory leaks in Python
Check for external commands in python
Try implementing extension method in python
Implemented label propagation method in Python
Simulate Monte Carlo method in Python
There is no switch in python
Hash method (open address method) in Python
Run unittests in Python (for beginners)
What to do if No Python documentation found for ... appears in pydoc
Method to build Python environment in Xcode 6
Notes on nfc.ContactlessFrontend () for nfcpy in python
Inject is recommended for DDD in Python
Revived from "no internet access" in Python
Tips for dealing with binaries in Python
Electron Microscopy Simulation in Python: Multislice Method (1)
Summary of various for statements in Python
Type annotations for Python2 in stub files!
In python + sqlite3 "OperationalError: no such column:"
Description method for reusing variables in shellscript
Template for writing batch scripts in python
Electron Microscopy Simulation in Python: Multislice Method (2)
Process multiple lists with for in Python
MongoDB for the first time in Python
Get a token for conoha in python
Sample for handling eml files in Python
AtCoder cheat sheet in python (for myself)
Call sudo in Python and autofill password
ModuleNotFoundError in Python: No module named story
I searched for prime numbers in python
Notes for using python (pydev) in eclipse
Tips for making small tools in python
[Python] Invert bool value in one line
Use pathlib in Maya (Python 2.7) for upcoming Python 3.7
Call APIGateWay with APIKey in python requests
Alignment algorithm by insertion method in Python
Import Error in Python3: No module named'xxxxx'
String → Bool value conversion in Python Consideration
You can call the method of the class directly in Python3 without adding @staticmethod
[Introduction to Udemy Python3 + Application] 37. Techniques for determining that there is no value
Template for creating command line applications in Python
CERTIFICATE_VERIFY_FAILED in Python 3.6, the official installer for macOS
++ and-cannot be used for increment / decrement in python
Instant method grammar for Python and Ruby (studying)
File DL, byte value and delete in Python3
Import-linter was useful for layered architecture in Python
Learn the design pattern "Template Method" in Python