I would like to know how to set attributes in python within a class. And tried the following code:
def __init__(self):
self.fecha_Y_Hs = datetime.datetime.now()
self.decripcion = ''
I am new in this language and I would like to know how I can declare and store in MySQL using a method to save using callproc () , so far I have this:
Method save ()
def guardar(self):
try:
conn = self.conexionMySQL()
myCursor = conn.cursor()
arg = [self.getfechaActual(), self.getDescripcion()]
myCursor.callproc('insertar_registro', arg)
conn.commit()
except Exception as e:
print("Se produjo el siguiente error al guardar: ", e)
finally:
myCursor.close()
conn.close()
Within the list I call the methods getfechaActual () and getDescription () which are the parameters I need to save in my bbdd. But it does not work for me.
Methods getfechaActual () and getDescription ()
def getfechaActual(self):
return self.fecha_Y_Hs
def getDescripcion(self):
return self.descripcion
I need to know how I can declare my attributes correctly so that I can then pass the necessary parameters to be stored in the bbdd. So then from another method call save () .
For example:
def nombre_metodo(param):
if condicion:
...
guardar()
The same thing in Java is done setting the Get And Setter but here I do not know how to do it since I'm raw on the subject, I'm missing a blow from a strong oven. Thanks again.