import psycopg2
class BaseDeDatos:
def _init_(self):
try:
self.conexion=psycopg2.connect(
"host='localhost' port='5432' dbname='Inversiones'
user='postgres' password='xxxxxx'")
self.conexion.autocommit = True
self.cursor = self.conexion.cursor()
except:
print("No se pudo conectar a la base de datos")
def crearTabla(self):
crearTablaComando = "CREATE TABLE Pet(name varchar(20)[], age integer
NOT NULL)"
self.cursor.execute(crearTablaComando)
if __name__=='_Base_de_datos_':
baseDeDatos=BaseDeDatos()
baseDeDatos.crearTabla
When I compile, I do not see any error, but when going to postgres, I do not see the new table, and I do not know if it is not connecting to the database or if it is not creating the table. If I do not put the if__name __... I get this error:
self.cursor.execute(crearTablaComando)
AttributeError: 'BaseDeDatos' object has no attribute 'cursor'
help, please. I'm starting in python, so do not be harsh with me :( haha