Python Note: When you want to know the attributes of an object

Basically, the attributes of objects are

John.age

You can get it by connecting'.', But if this is imported from the outside, ** "I think there is such an attribute, but I do not know the name (no, maybe not)" ** You may fall into a situation like that.

In such a case, google is the most reliable, but if you want to take a look, you can take a peek by doing the following, so I think it's worth remembering.

Example
import sys

print(sys)
# <module 'sys' (built-in)>
#I don't know what this means, but ...

print( dir(sys) )
# ['__displayhook__', '__doc__', '__excepthook__', '__name__', '__package__', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_getframe', '_mercurial', 'api_version', 'argv', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dont_write_bytecode', 'exc_clear', 'exc_info', 'exc_type', 'excepthook', 'exec_prefix', 'executable', 'exit', 'exitfunc', 'flags', 'float_info', 'float_repr_style', 'getcheckinterval', 'getdefaultencoding', 'getdlopenflags', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'gettrace', 'hexversion', 'last_traceback', 'last_type', 'last_value', 'long_info', 'maxint', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'ps1', 'ps2', 'py3kwarning', 'real_prefix', 'setcheckinterval', 'setdlopenflags', 'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'subversion', 'version', 'version_info', 'warnoptions']
#If this is the case, it may be possible to discover such attribute names.

Recommended Posts

Python Note: When you want to know the attributes of an object
How to know the internal structure of an object in Python
[Python] I want to know the variables in the function when an error occurs!
Get the attributes of an object
I want to know the features of Python and pip
[Python3] Code that can be used when you want to change the extension of an image at once
When you want to save the result of the callback function somewhere
When you want to send an object with requests using flask
When you want to use multiple versions of the same Python library (virtual environment using venv)
When you want to change the HTTP headers of Flask's test client
How to build an environment when you want to use python2.7 after installing Anaconda3
What you want to memorize with the basic "string manipulation" grammar of python
I want to store the result of% time, %% time, etc. in an object (variable)
How much do you know the basics of Python?
Python Note: The mystery of assigning a variable to a variable
[Introduction to Python] Basic usage of the library scipy that you absolutely must know
[Python] You can save an object to a file by using the pickle module.
Solution when you want to use cv_bridge with python3 (virtualenv)
[Django] A memorandum when you want to communicate asynchronously [Python3]
[Python] Change the Cache-Control of the object uploaded to Cloud Storage
[Python] If you suddenly want to create an inquiry form
Knowledge you need to know when programming competitive programming with Python2
An introduction to object orientation-let's change the internal state of an object
I want to know the legend of the IT technology world
When you want to hit a UNIX command on Python
A convenient function memo to use when you want to enter the debugger if an error occurs when running a Python script.
Make a note of what you want to do in the future with Raspberry Pi
I know? Data analysis using Python or things you want to use when you want with numpy
Key operations you want to know
[Python] When you want to import and use your own package in the upper directory
[Subprocess] When you want to execute another Python program in Python code
I want to know the weather with LINE bot feat.Heroku + Python
[Linux] I want to know the date when the user logged in
[Cloudian # 9] Try to display the metadata of the object in Python (boto3)
When you want to keep the Sphinx documentation theme as usual
I want to output the beginning of the next month with Python
I want to know if you install Python on Mac ・ Iroha
I want to run the Python GUI when starting Raspberry Pi
[Python] When you want to use all variables in another file
I want to know the population of each country in the world.
[python] A note that started to understand the behavior of matplotlib.pyplot
When you want to adjust the axis scale interval with APLpy
I want to extract an arbitrary URL from the character string of the html source with python
How to write when you want to put a number after the group number to be replaced with a regular expression in re.sub of Python
The story of making Python an exe
Note when creating an environment with python
[Python3] Rewrite the code object of the function
I didn't know the basics of Python
Python Note: The secret role of commas
If you want a singleton in python, think of the module as a singleton
[Note] I want to completely preprocess the data of the Titanic issue-Age version-
Have Alexa run Python to give you a sense of the future
If you want to include awsebcli with CircleCI, specify the python version
[Python] Calculate the number of digits required when filling in 0s [Note]
(Python Selenium) I want to check the settings of the download destination of WebDriver
I want to batch convert the result of "string" .split () in Python
I want to explain the abstract class (ABCmeta) of Python in detail.
[Python] If you want to draw a scatter plot of multiple clusters
I want to color a part of an Excel string in Python
__Getattr__ and __getattribute__ to customize the acquisition of object attributes by dots
Memorandum of means when you want to make machine learning with 50 images