当前位置: 首页>>代码示例>>Python>>正文


Python psycopg.connect函数代码示例

本文整理汇总了Python中psycopg.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: abre_coneccion

 def abre_coneccion(self):
     try:
         f = open("coneccion.rc", 'r')
         l = f.readline()[:-1]
         self.cnx = connect(l)
         f.close()
         print "Conección por archivo"
     except:
         DB = config.DB
         user = config.user
         password = config.password
         host = config.host
 
         self.cnx = connect(DB + " " + user + " " + password + " " + host )
         print "Conección base"
开发者ID:esanmartin,项目名称:agro,代码行数:15,代码来源:wnAgro.py

示例2: __init__

	def __init__(self, hostname, dbname, schema, source_table, target_table, offset, limit, \
		output, bonferroni=0, report=0, log=0, wu=0, needcommit=0):
		self.conn = psycopg.connect('host=%s dbname=%s'%(hostname, dbname))
		self.curs = self.conn.cursor()
		self.curs.execute("set search_path to %s"%schema)
		self.source_table = source_table
		self.target_table = target_table
		self.offset = offset
		self.limit = limit
		self.output = output
		if self.output:
			#filename exists
			self.outf = open(self.output, 'w')

		self.bonferroni = int(bonferroni)
		self.report = int(report)
		self.log = int(log)
		self.wu = int(wu)
		self.needcommit = int(needcommit)
		self.global_go_id_to_no_dict = {}
		self.global_go_no_to_size_dict = {}
		self.global_gene_to_go_dict = {}
		self.no_of_records = 0
		if self.log:
			self.logfile = open('/tmp/cluster_stat.log','w')
		self.cluster_memory = {}
开发者ID:polyactis,项目名称:annot,代码行数:26,代码来源:cluster_stat.py

示例3: __init__

	def __init__(self, hostname, dbname, schema, table, branch, depth, all, new_table, report=0, \
		needcommit=0, log=0):
		self.conn = psycopg.connect('host=%s dbname=%s'%(hostname, dbname))
		self.curs = self.conn.cursor()
		self.curs.execute("set search_path to %s"%schema)
		self.table = table
		
		self.depth = int(depth)
		self.all = int(all)
		self.new_table = int(new_table)
		self.report = int(report)
		self.needcommit = int(needcommit)
		self.log = int(log)
		
		#mapping for the branches
		self.branch_dict = {0:'molecular_function',
			1:'biological_process',
			2:'cellular_component'}
		self.branch = self.branch_dict[int(branch)]
		if self.log:
			self.log_file = open('/tmp/go_node_distance.log','w')
		#mapping between go term id and its index list
		self.go_id2index = {}
		#mapping between go_id and go_acc
		self.go_id2acc = {}
		#GO DAG (directed)
		self.go_digraph = Graph.Graph()
		#GO undirected Graph, to compute distance between two nodes
		self.go_graph = Graph.Graph()
		#the node_list contains the nodes to compute pairwise distances
		self.node_list = Set()
		#the list containing all indices
		self.index_list = Set()
		#key structure, mapping between a pair of go_id's and its associated distances
		self.go_id2distance = {}
开发者ID:polyactis,项目名称:annot,代码行数:35,代码来源:go_node_distance.py

示例4: __init__

	def __init__(self, hostname, dbname, schema, source_table, target_table, prune_type, threshhold, report, log=0, needcommit=0):
		self.conn = psycopg.connect('host=%s dbname=%s'%(hostname, dbname))
		self.curs = self.conn.cursor()
		self.curs.execute("set search_path to %s"%schema)
		self.source_table = source_table
		self.target_table = target_table
		self.prune_type = int(prune_type)
		self.threshhold = float(threshhold)
		self.report = int(report)
		self.log = int(log)
		self.needcommit = int(needcommit)
		self.prune_func_dict = {0:self.prune_on_edge_set,
			1:self.prune_on_recurrence_array,
			2:self.prune_on_vertex_set}
		#a function mapping structure.
		self.vertex_set_dict = {}
		#store a edge_set_dict or recurrence_pattern_dict with the same vertex_set
		self.mcl_id2connectivity_dict ={}
		#store the mcl_id:connectivity pair
		self.good_mcl_id_dict = {}
		#the mcl_id:recurrence_array pair dictionary
		self.bad_mcl_id_list = []
		#store the mcl_ids that are going to be deleted.
		if self.log:
			self.log_file = open("/tmp/cluster_prune.log", 'w')
		self.no_of_goods = 0
		self.no_of_bads = 0
		self.run_no = 0
		self.remaining = 1	#1 is useful to let the first run start
		#two tables for bucketing
		self.src_table = 'src_tmp'
		self.tg_table = 'tg_tmp'
开发者ID:polyactis,项目名称:annot,代码行数:32,代码来源:cluster_prune.py

示例5: __init__

	def __init__(self, dir, hostname, dbname, schema, orgn, union=0, needcommit=0):
		self.dir = dir
		self.conn = psycopg.connect('host=%s dbname=%s'%(hostname, dbname))
		self.curs = self.conn.cursor()
		self.curs.execute("set search_path to %s"%schema)
		self.union = int(union)
		self.needcommit = int(needcommit)
		self.org_short2long = {'at':'Arabidopsis thaliana',
			'ce':'Caenorhabditis elegans',
			'dm':'Drosophila melanogaster',
			'hs':'Homo sapiens',
			'mm':'Mus musculus',
			'sc':'Saccharomyces cerevisiae',
			'Arabidopsis thaliana':'Arabidopsis thaliana',
			'Caenorhabditis elegans':'Caenorhabditis elegans',
			'Drosophila melanogaster':'Drosophila melanogaster',
			'Homo sapiens':'Homo sapiens',
			'Mus musculus':'Mus musculus',
			'Gorilla gorilla Pan paniscus Homo sapiens':'Homo sapiens',
			'Saccharomyces cerevisiae':'Saccharomyces cerevisiae'}
		self.organism = self.org_short2long[orgn]
		#mapping between gene_id and gene_no
		self.gene_id2gene_no = {}
		#mapping between gene_id and its occurence
		self.gene_id2freq = {}
		#unique gene collection, for database submission
		self.gene_set = Set()
开发者ID:polyactis,项目名称:annot,代码行数:27,代码来源:gene_table.py

示例6: __init__

    def __init__(self, hostname, dbname, schema, type, output, orgn="sc"):
        self.conn = psycopg.connect("host=%s dbname=%s" % (hostname, dbname))
        self.curs = self.conn.cursor()
        self.curs.execute("set search_path to %s" % schema)

        self.type_dict = {0: "molecular_function", 1: "biological_process", 2: "cellular_component"}
        self.type = self.type_dict[int(type)]
        self.ofname = output
        self.org_short2long = {
            "at": "Arabidopsis thaliana",
            "ce": "Caenorhabditis elegans",
            "dm": "Drosophila melanogaster",
            "hs": "Homo sapiens",
            "mm": "Mus musculus",
            "sc": "Saccharomyces cerevisiae",
            "Arabidopsis thaliana": "Arabidopsis thaliana",
            "Caenorhabditis elegans": "Caenorhabditis elegans",
            "Drosophila melanogaster": "Drosophila melanogaster",
            "Homo sapiens": "Homo sapiens",
            "Mus musculus": "Mus musculus",
            "Gorilla gorilla Pan paniscus Homo sapiens": "Homo sapiens",
            "Saccharomyces cerevisiae": "Saccharomyces cerevisiae",
        }
        self.organism = self.org_short2long[orgn]
        self.log_file = open("/tmp/GO_graphxml.log", "w")
        self.termid_dict = {}
        self.acc2id_dict = {}
        self.go_graph = Graph.Graph()
开发者ID:polyactis,项目名称:annot,代码行数:28,代码来源:GO_graphxml.py

示例7: load

    def load(self):
        '''Load state from database'''

        import psycopg
        
        if options["globals", "verbose"]:
            print >> sys.stderr, 'Loading state from',self.db_name,'database'

        self.db = psycopg.connect(self.db_name)

        c = self.cursor()
        try:
            c.execute("select count(*) from bayes")
        except psycopg.ProgrammingError:
            self.db.rollback()
            self.create_bayes()
        
        if self._has_key(self.statekey):
            row = self._get_row(self.statekey)
            self.nspam = row["nspam"]
            self.nham = row["nham"]
            if options["globals", "verbose"]:
                print >> sys.stderr, ('%s is an existing database,'
                                      ' with %d spam and %d ham') \
                      % (self.db_name, self.nspam, self.nham)
        else:
            # new database
            if options["globals", "verbose"]:
                print >> sys.stderr, self.db_name,'is a new database'
            self.nspam = 0
            self.nham = 0
开发者ID:ArildF,项目名称:rogie,代码行数:31,代码来源:storage.py

示例8: _cursor

    def _cursor(self, settings):
        set_tz = False
        if self.connection is None:
            set_tz = True
            if settings.DATABASE_NAME == "":
                from django.core.exceptions import ImproperlyConfigured

                raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.")
            conn_string = "dbname=%s" % settings.DATABASE_NAME
            if settings.DATABASE_USER:
                conn_string = "user=%s %s" % (settings.DATABASE_USER, conn_string)
            if settings.DATABASE_PASSWORD:
                conn_string += " password='%s'" % settings.DATABASE_PASSWORD
            if settings.DATABASE_HOST:
                conn_string += " host=%s" % settings.DATABASE_HOST
            if settings.DATABASE_PORT:
                conn_string += " port=%s" % settings.DATABASE_PORT
            self.connection = Database.connect(conn_string, **self.options)
            self.connection.set_isolation_level(1)  # make transactions transparent to all cursors
        cursor = self.connection.cursor()
        if set_tz:
            cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
        cursor.execute("SET client_encoding to 'UNICODE'")
        cursor = UnicodeCursorWrapper(cursor, "utf-8")
        return cursor
开发者ID:paulo-sergio-softlog,项目名称:geraldo,代码行数:25,代码来源:base.py

示例9: __init__

	def __init__(self, hostname, dbname, schema, type, output, orgn='sc'):
		self.conn = psycopg.connect('host=%s dbname=%s'%(hostname, dbname))
		self.curs = self.conn.cursor()
		self.curs.execute("set search_path to %s"%schema)
		
		self.type_dict = {0:'molecular_function', 1:'biological_process', 2:'cellular_component'}
		self.type = self.type_dict[int(type)]
		self.ofname = output
		self.org_short2long = {'at':'Arabidopsis thaliana',
			'ce':'Caenorhabditis elegans',
			'dm':'Drosophila melanogaster',
			'hs':'Homo sapiens',
			'mm':'Mus musculus',
			'sc':'Saccharomyces cerevisiae',
			'Arabidopsis thaliana':'Arabidopsis thaliana',
			'Caenorhabditis elegans':'Caenorhabditis elegans',
			'Drosophila melanogaster':'Drosophila melanogaster',
			'Homo sapiens':'Homo sapiens',
			'Mus musculus':'Mus musculus',
			'Gorilla gorilla Pan paniscus Homo sapiens':'Homo sapiens',
			'Saccharomyces cerevisiae':'Saccharomyces cerevisiae'}
		self.organism = self.org_short2long[orgn]
		self.log_file = open('/tmp/GO_graphxml.log', 'w')		
		self.termid_dict = {}
		self.acc2id_dict = {}
		self.go_graph = Graph.Graph()
开发者ID:polyactis,项目名称:annot,代码行数:26,代码来源:GO_graphxml.py

示例10: __init__

	def __init__(self, hostname, dbname, schema, orgn, needcommit=0):
		"""
		08-30-05
			add rn to org_short2long
			remove self.organism
		"""
		self.conn = psycopg.connect('host=%s dbname=%s'%(hostname, dbname))
		self.curs = self.conn.cursor()
		self.curs.execute("set search_path to %s"%schema)
		self.needcommit = int(needcommit)
		self.org_short2long = {'at':'Arabidopsis thaliana',
			'ce':'Caenorhabditis elegans',
			'dm':'Drosophila melanogaster',
			'hs':'Homo sapiens',
			'mm':'Mus musculus',
			'sc':'Saccharomyces cerevisiae',
			'rn':'Rattus norvegicus',
			'Rattus norvegicus':'Rattus norvegicus',
			'Arabidopsis thaliana':'Arabidopsis thaliana',
			'Caenorhabditis elegans':'Caenorhabditis elegans',
			'Drosophila melanogaster':'Drosophila melanogaster',
			'Homo sapiens':'Homo sapiens',
			'Mus musculus':'Mus musculus',
			'Gorilla gorilla Pan paniscus Homo sapiens':'Homo sapiens',
			'Saccharomyces cerevisiae':'Saccharomyces cerevisiae'}
		#mapping between gene_no and GO list
		self.geneno_go_dict = {}
		#mapping between gene_no and gene_id
		self.geneno_to_geneid = {}
开发者ID:polyactis,项目名称:annot,代码行数:29,代码来源:gene_go_functions.py

示例11: __init__

	def __init__(self, dir, hostname, dbname, orgn, log, needcommit=0):
		self.dir = dir
		self.conn = psycopg.connect('host=%s dbname=%s'%(hostname, dbname))
		self.curs = self.conn.cursor()
		self.curs.execute("set search_path to graph")
		self.org_short2long = {'at':'Arabidopsis thaliana',
			'ce':'Caenorhabditis elegans',
			'dm':'Drosophila melanogaster',
			'hs':'Homo sapiens',
			'mm':'Mus musculus',
			'sc':'Saccharomyces cerevisiae',
			'Arabidopsis thaliana':'Arabidopsis thaliana',
			'Caenorhabditis elegans':'Caenorhabditis elegans',
			'Drosophila melanogaster':'Drosophila melanogaster',
			'Homo sapiens':'Homo sapiens',
			'Mus musculus':'Mus musculus',
			'Gorilla gorilla Pan paniscus Homo sapiens':'Homo sapiens',
			'Saccharomyces cerevisiae':'Saccharomyces cerevisiae'}
		self.organism = self.org_short2long[orgn]
		self.log = int(log)
		if self.log:
			self.logfile = open('/tmp/gene_id_to_no.log', 'w')
		self.needcommit = int(needcommit)
		#records down the maximum gene_no ever assigned.
		self.max_gene_no = 0
		#mapping between gene_id and gene_no
		self.vertex_dict = {}
		self.vertex_dict_extension = {}
		#a unique collection of all genes in the datasets of the directory
		self.gene_set = Set()
开发者ID:polyactis,项目名称:annot,代码行数:30,代码来源:gene_id_to_no.py

示例12: __init__

	def __init__(self, hostname, dbname, schema, table, mcl_table, tag, p_value_list, unknown_list, connectivity_list,\
			recurrence_list, size_list, leave_one_out, wu, judger_type, depth_list, dir_files=None, dominant=0, needcommit=0,\
			needcommit_of_gene_stat=0, gene_table='p_gene'):
		self.hostname = hostname
		self.dbname = dbname
		self.schema = schema
		self.conn = psycopg.connect('host=%s dbname=%s'%(hostname, dbname))
		self.curs = self.conn.cursor()
		self.curs.execute("set search_path to %s"%schema)
		self.table = table
		self.mcl_table = mcl_table
		self.tag = tag
		self.p_value_list = p_value_list
		self.unknown_list = unknown_list
		self.connectivity_list = connectivity_list
		self.recurrence_list = recurrence_list
		self.cluster_size_list = size_list
		self.leave_one_out = int(leave_one_out)
		self.wu = int(wu)
		self.judger_type = int(judger_type)
		self.depth_list = depth_list
		self.dir_files = dir_files
		self.dominant = int(dominant)
		self.needcommit = int(needcommit)
		#a dictionary mapping the user choices to stat classes
		#self.stat_class_dict = {1: gene_stat,
		#	0: gene_stat_on_mcl_result}
		self.stat_data = []


		#default parameters to invoke gene_stat
		self.report = 0
		self.log = 0
		self.needcommit_of_gene_stat = int(needcommit_of_gene_stat)
		self.gene_table = gene_table
开发者ID:polyactis,项目名称:annot,代码行数:35,代码来源:batch_stat.py

示例13: _cursor

 def _cursor(self, settings):
     set_tz = False
     if self.connection is None:
         set_tz = True
         if settings.DATABASE_NAME == '':
             from django.core.exceptions import ImproperlyConfigured
             raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.")
         conn_string = "dbname=%s" % settings.DATABASE_NAME
         if settings.DATABASE_USER:
             conn_string = "user=%s %s" % (settings.DATABASE_USER, conn_string)
         if settings.DATABASE_PASSWORD:
             conn_string += " password='%s'" % settings.DATABASE_PASSWORD
         if settings.DATABASE_HOST:
             conn_string += " host=%s" % settings.DATABASE_HOST
         if settings.DATABASE_PORT:
             conn_string += " port=%s" % settings.DATABASE_PORT
         self.connection = Database.connect(conn_string, **self.options)
         self.connection.set_isolation_level(1) # make transactions transparent to all cursors
     cursor = self.connection.cursor()
     if set_tz:
         cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
         if not hasattr(self, '_version'):
             version = get_version(cursor)
             self.__class__._version = version
             if version < (8, 0):
                 # No savepoint support for earlier version of PostgreSQL.
                 self.features.uses_savepoints = False
     cursor.execute("SET client_encoding to 'UNICODE'")
     cursor = UnicodeCursorWrapper(cursor, 'utf-8')
     return cursor
开发者ID:hugs,项目名称:django,代码行数:30,代码来源:base.py

示例14: sql_open_connection

 def sql_open_connection(self):
     db = connection_dict(self.config, 'database')
     logging.getLogger('hyperdb').info('open database %r'%db['database'])
     try:
         conn = psycopg.connect(**db)
     except psycopg.OperationalError, message:
         raise hyperdb.DatabaseError, message
开发者ID:fillarikanava,项目名称:old-fillarikanava,代码行数:7,代码来源:back_postgresql.py

示例15: __init__

	def __init__(self, fname, dbname, schema, needcommit=0):
		self.reader = csv.reader(open(fname, 'r'), delimiter='\t')
		self.conn = psycopg.connect('dbname=%s'%dbname)
		self.curs = self.conn.cursor()
		self.curs.execute("set search_path to %s"%schema)
		self.needcommit = int(needcommit)
		self.go_id_dict = {}
开发者ID:polyactis,项目名称:annot,代码行数:7,代码来源:go_index.py


注:本文中的psycopg.connect函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。