how to verify if variable exist in parent class in python
I have to add all the variables exist in parent class in one list in child class. However all the variables in the parent class is not mandatory. Is there any way i can figure out if variable exist in parent class or not ??
>>> class A(object): ... pass ... >>> class B(A): ... pass ... >>> B.__bases__ (<class '__main__.A'>,) >>> getattr(B.__bases__,'x',False) False Or more comprehensivley: class A(object): x = 5 class B(A): y = 6 x = 7 print(getattr(B.__bases__,'y',False)) print(getattr(B.__bases__,'x',False)) Outputs False 5 >>> So just check wether or not False is returned, if it is then you can conclude the attribute doesn't exist in the parent class.
If you know what attributes you're looking for, you can match them against dir(parent class)
How to assign current date to a date field in odoo v8?
How can I query Google App Engine entities by name to convert to new names?
How to set socks5 proxy in dryscrape python?
How does pyaramorph (Arabic morphological analyzer) work? [closed]
Convert UTC to local time
Python Kivy: Get Music hotkeys signal of phone/headphones
IPython - ipython_notebook_config.py missing
How to implicitly use the base definition of a method
Creat List of URLs for grequest
Create directory and write files to a remote, password protected computer
jinja2 encoding error in python
mysql.connector, multi=True, sql variable assignment not working
Geo Pandas Data Frame / Matrix - filter/drop NaN / False values
pip django-lfs gives error
Graph API image upload - permission issues
Why does “print ('\033[0m')” barf on Python 2.7.6 Ubuntu 14.04 LTS