Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/05/2010, 07:35
Avatar de Nekeniehl
Nekeniehl
 
Fecha de Ingreso: julio-2009
Ubicación: Berlin, Alemania / Granada, España
Mensajes: 132
Antigüedad: 14 años, 9 meses
Puntos: 6
A ver a ver, Que alguien me aclare

Veamos tengo este codigo:

Código Python:
Ver original
  1. #!/usr/bin/python
  2. import MySQLdb
  3.  
  4. def __init__ (self):
  5.     pass
  6.  
  7. def Conn (self):
  8.     """Connection to mysql"""
  9.     host    = "localhost"
  10.     database= "test"
  11.     username= "root"
  12.     password= "1234"
  13.     db=MySQLdb.connect(host,username,password,database)
  14.     return db
  15.  
  16. db=Conn
  17. cursor=db.cursor()
  18. sql='SELECT * FROM test;'
  19. cursor.execute(sql)
  20. resultado=re.fetchall()
  21. for registro in resultado:
  22.     print registro[0]

y estan simple que me dá verguenza hasta ponerlo, pero es que soy newie en python (hoy) y ya le estoy cogiendo coraje, no entiendo como algo tan simple me puede estar dando tantos problemas, me arroja:

Código:
Traceback (most recent call last):
  File "~/src/reportingtool.py", line 18, in <module>
    cursor=db.cursor()
AttributeError: 'function' object has no attribute 'cursor'
¿Alguien me explica que pasa?