Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am working on python plugins for QGIS. I have my and files. I connected it to database using Connection class and under def __init__(self, uri=None) in file. I want to connect to database through file.I imported into But how to call def __init__(self, uri=None) of from I need to create instance of 'Connection' class in order to call def __init__(self, uri=None) method of in How do I go about it? file:

class Connection(DbConn.Connection):

def getTypeName(self):
    return 'postgis'

def getTypeNameString(self):
    return 'PostgreSQL'

def getProviderName(self):
    return 'postgres'

def getSettingsKey(self):
    return 'PostgreSQL'

def icon(self):
    return QIcon(":/icons/postgis_elephant.png")


def __init__(self, uri=None):

    DbConn.Connection.__init__(self, uri) =
    #self.port = uri.port()
    #self.dbname = uri.database()
    #self.user = uri.username()
    #self.passwd = uri.password() ='localhost' 
    self.port =5432 
    self.dbname ='ssss'
    self.user = 'j'
    self.passwd = 'jkj'

    if self.dbname == '' or self.dbname is None:
        self.dbname = self.user

        self.con = psycopg2.connect(self.con_info())
    except psycopg2.OperationalError, e:
        raise DbError(e)

    self.has_spatial = self.check_spatial()


    # a counter to ensure that the cursor will be unique
    self.last_cursor_id = 0
if __name__ == "__main__":
window = Connection()

and is:

import sys
import pdb

from PyQt4 import QtGui, QtCore
import psycopg2
import pprint

#from qgis.core import *
#from qgis.gui import *

import postgis

from DatabaseModel import TableItem, SchemaItem, DatabaseModel
import DbConnection

from ui.DlgQueryBuilder_ui import Ui_Dialog
from DlgDbError import DlgDbError

from QueryParser import QueryParser
from QueryManager import *

class DlgQueryBuilder(QDialog, Ui_Dialog):
    so on.....
share|improve this question
Can you post the relevant sections of your code in your question please. It's hard to understand how your code is written. – Nathan W Feb 8 '12 at 10:02
ok sure........ – Poonam Narvekar Feb 8 '12 at 10:24

1 Answer 1

up vote 1 down vote accepted

This should work:


import postgis
conn = postgis.Connection()


from postgis import Connection
conn = Connection()
share|improve this answer
thanx a lot:).. – Poonam Narvekar Feb 8 '12 at 12:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.