Can't instantiate Python class even though it's being imported

Viewed 137

I'm writing a Python package that looks like this:

|- datum/
    |- __init__.py
    |- database.py

__init__.py

from .database import Database

def connect(url):
    print(Database)         # for debugging
    return Database(url)

database.py

class Database(object):
    def __init__(self, url):
        self.url = url

    ...more methods

This is installed as a package called datum in development mode. If I call connect outside of this package like:

import datum
db = datum.connect('postgresql://xxx')

...this is the output:

<class 'datum.database.Database'>
Traceback (most recent call last):
  File "Z:\AIS\Flask\ais\engine\scripts\load_pwd_parcels.py", line 30, in <module>
    source_db = Database(source_db_url)
NameError: name 'Database' is not defined

I'm confused because the class is being imported fine -- I can print it and even run dir on it and see all my methods -- but when I try to instantiate something it's "not defined". Does anyone know what I'm doing wrong here?

1 Answers
Related