get_obj_attr

pyhelpers.ops.get_obj_attr(obj, col_names=None, as_dataframe=False)

Get main attributes of an object.

Parameters
  • obj (object) – an object, e.g. a class

  • col_names (list) – a list of column names

  • as_dataframe (bool) – whether to return the data in tabular format, defaults to False

Returns

list or tabular data of the main attributes of the given object

Return type

pandas.DataFrame

Examples:

>>> from pyhelpers.ops import get_obj_attr
>>> from pyhelpers.dbms import PostgreSQL

>>> postgres = PostgreSQL()
Password (postgres@localhost:5432): ***
Connecting postgres:***@localhost:5432/postgres ... Successfully.

>>> obj_attr = get_obj_attr(postgres, as_dataframe=True)
>>> obj_attr.head()
          attribute       value
0  DEFAULT_DATABASE    postgres
1   DEFAULT_DIALECT  postgresql
2    DEFAULT_DRIVER    psycopg2
3      DEFAULT_HOST   localhost
4      DEFAULT_PORT        5432

>>> obj_attr.Attribute.to_list()
['DEFAULT_DATABASE',
 'DEFAULT_DIALECT',
 'DEFAULT_DRIVER',
 'DEFAULT_HOST',
 'DEFAULT_PORT',
 'DEFAULT_SCHEMA',
 'DEFAULT_USERNAME',
 'address',
 'database_info',
 'database_name',
 'engine',
 'host',
 'port',
 'url',
 'username']