Global function in __init__.py not accessible using Pylons + Python

I'm having trouble creating a global function accessible from within all classes. I receive an error from within user.py that says:

NameError: global name 'connectCentral' is not defined

Here is my current code.

project/model/__ init __.py:

    """The application's model objects"""
    import sqlalchemy as sa
    from sqlalchemy import orm
    from sqlalchemy import engine_from_config

    from pylons import config
    import central

    #Establish an on-demand connection to the central database
    def connectCentral():
        engine = engine_from_config(config, 'sqlalchemy.central.')
        central.engine = engine
        central.Session.configure(bind=engine)

project/model/user.py

    import project.model

    class User(object):
        def emailExists(self):
            try:
                connectCentral()
                emails = central.Session.query(User).filter_by(email=self.email).count()
            if (emails > 0):
                return False
            else:
                return True

        except NameError:
            self.errors['email'] = 'E-Mail not set'
            return False

Am I missing an import? Is there a better way to do this?

Thanks.

Answers


You need to qualify the name with the module (or package) it's in, so:

        try:
            project.model.connectCentral()

etc.


Need Your Help

declaring a string in assembly

c assembly inline-assembly

I have this assembly code that computes some prime numbers:

Update file in Windows Azure CDN

cdn windows-azure-storage

I have blob storage and CDN endpoint, that store my static content.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.