Pastebin

Paste #573: No description

< previous paste - next paste>

Pasted by Anonymous Coward

Download View as text

contacts_connect.py:
--------------------
from pg import connect

def contacts_connect():
    dbname = "tdn_contacts"
    host   = "localhost"
    port   = 5432
    opt    = None
    tty    = None
    user   = "tdn_dev"
    passwd = ""
    
    try:
        print "Connecting..."
        connection = connect(dbname, host, port, opt, tty, user, passwd)
    except:
        print "Could not connect to database."
        connection = None
    return connection





contacts.py
-----------
from contacts_connect import contacts_connect

db = contacts_connect
query = db.query("""SELECT first_name, last_name, email1, email2 
    FROM contact
    WHERE zipcode IS NOT NULL
    ORDER BY last_name ASC, first_name ASC""")
    
for line in query.getresult():
   print
   first_name, last_name, email1, email2 = line[1:]
   print "%s -- %s, %s, %s, %s" % (line[0], first_name, last_name, email1, email2)





output:
-------
tdn@bart) (07-05-23 23:30) (P:1 L:1) [0]                                                                                  [ 23:30:23 up 2 days, 16:51,  1 user,  load average: 0.41, 0.37, 0.31]
~/tmp/rgb $ python contacts.py
Traceback (most recent call last):
  File "contacts.py", line 4, in <module>
    query = db.query("""SELECT first_name, last_name, email1, email2
AttributeError: 'function' object has no attribute 'query'
(tdn@bart) (07-05-23 23:30) (P:1 L:1) [1]                                                                                  [ 23:30:26 up 2 days, 16:51,  1 user,  load average: 0.38, 0.37, 0.30]
~/tmp/rgb $                                                                                            

New Paste


Do not write anything in this field if you're a human.

Go to most recent paste.