Search code examples
pythonpostgresqlpygresql

AttributeError: get_tables


What is the problem of this code? Should show a list of tables

import pg

con = pg.connect(dbname='xxx', host='xxxx', user='xxx')
pgqueryset = con.get_tables()

Traceback (most recent call last):
  File "demo.py", line 42, in <module>
    pgqueryset = con.get_tables()()
AttributeError: get_tables

Docs

Parameters:
None
Returns:
list:   all tables in connected database

Solution

  • get_tables is on the DB class, which is initialised with the same arguments as connect():

    Try:

    db = pg.DB(dbname='xxx', host='xxxx', user='xxx')
    pgqueryset = db.get_tables()