I have the following class:
class RegC100:
def __init__(self,linha):
def convFloat(valor):
if (valor != ''):
valor = float(valor.replace(",", "."))
return valor
else:
return ''
def convInt(valor):
if(valor !=''):
valor = int(valor)
return valor
else:
return ''
def convData(valor):
if(valor != ''):
valorDia = valor[0:2]
valorMes = valor[2:4]
valorAno = valor[4:8]
valor = str(valorAno+'-'+valorMes+'-'+valorDia)
return valor
else:
return ''
self.linha = linha
l = linha.split('|')
self.reg = l[1]
self.indOper = l[2]
self.indEmit = l[3]
self.codPart = l[4]
self.codMod = l[5]
self.codSit = l[6]
self.ser = convInt(l[7])
self.numDoc = convInt(l[8])
self.chvNfe = l[9]
self.dtDoc = convData(l[10])
self.dtES = l[11]
self.vlDoc = convFloat(l[12])
self.indPgto = convInt(l[13])
self.vlDesc = convFloat(l[14])
self.vlAbatNt = convFloat(l[15])
self.vlMerc = convFloat(l[16])
self.indFrt = l[17]
self.vlFrt = convFloat(l[18])
self.vlSeg = convFloat(l[19])
self.vlOutDa = convFloat(l[20])
self.vlBcIcms = convFloat(l[21])
self.vlIcms = convFloat(l[22])
self.vlBcIcmsSt = convFloat(l[23])
self.vlIcmsSt = convFloat(l[24])
self.vlIpi = convFloat(l[25])
self.vlPis = convFloat(l[26])
self.vlCofins = convFloat(l[27])
self.vlPisSt = convFloat(l[28])
self.vlCofinsSt = convFloat(l[29])
which receives the following data:
|C100|0|1|99900821|55|00|2|000021255|23121207792435000327550020000212551005939150|20122012|20122012|899,00|2|||899,00|0||||0|0||||||||
I would like to make this my class return the values of my attributes as key and value or it may be an option to prepare this data to add to the database without having to be typing each attribute again. Is there any way? As I am very new to this python world, I also wanted to know if there is anything I can improve on in my class. Thanks in advance for your help.