Shelve giving NoneType error even though it's there (Python)









up vote
0
down vote

favorite












I'm trying to append to a list to then persist data in my shelve db



I have a file "base_de_datos" where I have my lists
Then I have a file "gestionador" where I load or save data



# ___base_de_datos___
clientes =
asesores =
solicitudes =


My code works for clientes and asesores but keeps dying at solicitudes it gives me a KeyError



# _____gestionador_____
import shelve
import base_de_datos as bd

def cargar_datos():
'''carga los datos en listas para su uso'''
bd.clientes = cargar_lista("clientes", "Clientes")
bd.asesores = cargar_lista("asesores", "Asesores")
bd.solicitudes = cargar_lista("solicitudes", "Solicitudes")

def guardar_datos():
'''guarda los datos en las listas en archivos para la persistencia'''
guardar_lista(bd.clientes,"Clientes", "clientes")
guardar_lista(bd.asesores,"Asesores", "asesores")
guardar_lista(bd.solicitudes,"Solicitudes", "solicitudes")

def cargar_lista(clave, nombreArchivo):
'''carga los datos al sistema cuando se este ejecutando'''
try:
basededatos = shelve.open(nombreArchivo)
lista = basededatos[clave]

if lista is None:
lista =


return lista

except KeyError:
return print("ERROR Ocurrio un al encontrar los datos")

def guardar_lista(objeto,nombreArchivo, clave):
''' funcion que sirve para guardar los datos en basededatos'''
try:
basededatos = shelve.open(nombreArchivo,'n')
basededatos[clave] = objeto
except FileNotFoundError:
print("ERROR Archivo no existe")

else:
basededatos.close()
basededatos = None


This is how I call Solicitudes



def add_solicitud(self):
datos = Solicitud.promp_init()
solicitud = Solicitud(**datos)
base_de_datos.solicitudes.append(solicitud)
gestionador.guardar_datos()


My class Solicitudes, where I have the method promp_init()



class Boleta(metaclass=ABCMeta):
@abstractmethod
def __init__(self):
pass

class Solicitud(Boleta):
def __init__(self, date='' , cliente='', asesor=''):
super().__init__()
self.date= date
self.cliente = cliente
self.asesor = asesor

def promp_init():
date= datetime.now()
print("The date is the actual date")
cliente=input_entero()
asesor=input_entero()
return dict(
"date": date,
"cliente": cliente,
"asesor": asesor
)


I get the error once I finish typing Solicitud's data



'NoneType' object has no attribute 'append'


When I debug on pycharm I already get a KeyError when trying to open the file for Solicitudes at the the method cargar_lista I added



if lista is None:
lista =


because I was told I needed to initialize it first which it worked but after a while the same thing happened again



Edit: Somehow started working, I think It's an error that happens whenever I add a new list to "base_de_datos" and it needs to be initialize.










share|improve this question























  • could you post the full stack trace of error?
    – Paritosh Singh
    Nov 11 at 17:19










  • Please include the full traceback, so we don't have to guess exactly what the context is.
    – Martijn Pieters
    Nov 11 at 17:21










  • Thank you for the response, how do I get the full traceback? is it the errors I get on the console?
    – Javier Heisecke
    Nov 11 at 17:38














up vote
0
down vote

favorite












I'm trying to append to a list to then persist data in my shelve db



I have a file "base_de_datos" where I have my lists
Then I have a file "gestionador" where I load or save data



# ___base_de_datos___
clientes =
asesores =
solicitudes =


My code works for clientes and asesores but keeps dying at solicitudes it gives me a KeyError



# _____gestionador_____
import shelve
import base_de_datos as bd

def cargar_datos():
'''carga los datos en listas para su uso'''
bd.clientes = cargar_lista("clientes", "Clientes")
bd.asesores = cargar_lista("asesores", "Asesores")
bd.solicitudes = cargar_lista("solicitudes", "Solicitudes")

def guardar_datos():
'''guarda los datos en las listas en archivos para la persistencia'''
guardar_lista(bd.clientes,"Clientes", "clientes")
guardar_lista(bd.asesores,"Asesores", "asesores")
guardar_lista(bd.solicitudes,"Solicitudes", "solicitudes")

def cargar_lista(clave, nombreArchivo):
'''carga los datos al sistema cuando se este ejecutando'''
try:
basededatos = shelve.open(nombreArchivo)
lista = basededatos[clave]

if lista is None:
lista =


return lista

except KeyError:
return print("ERROR Ocurrio un al encontrar los datos")

def guardar_lista(objeto,nombreArchivo, clave):
''' funcion que sirve para guardar los datos en basededatos'''
try:
basededatos = shelve.open(nombreArchivo,'n')
basededatos[clave] = objeto
except FileNotFoundError:
print("ERROR Archivo no existe")

else:
basededatos.close()
basededatos = None


This is how I call Solicitudes



def add_solicitud(self):
datos = Solicitud.promp_init()
solicitud = Solicitud(**datos)
base_de_datos.solicitudes.append(solicitud)
gestionador.guardar_datos()


My class Solicitudes, where I have the method promp_init()



class Boleta(metaclass=ABCMeta):
@abstractmethod
def __init__(self):
pass

class Solicitud(Boleta):
def __init__(self, date='' , cliente='', asesor=''):
super().__init__()
self.date= date
self.cliente = cliente
self.asesor = asesor

def promp_init():
date= datetime.now()
print("The date is the actual date")
cliente=input_entero()
asesor=input_entero()
return dict(
"date": date,
"cliente": cliente,
"asesor": asesor
)


I get the error once I finish typing Solicitud's data



'NoneType' object has no attribute 'append'


When I debug on pycharm I already get a KeyError when trying to open the file for Solicitudes at the the method cargar_lista I added



if lista is None:
lista =


because I was told I needed to initialize it first which it worked but after a while the same thing happened again



Edit: Somehow started working, I think It's an error that happens whenever I add a new list to "base_de_datos" and it needs to be initialize.










share|improve this question























  • could you post the full stack trace of error?
    – Paritosh Singh
    Nov 11 at 17:19










  • Please include the full traceback, so we don't have to guess exactly what the context is.
    – Martijn Pieters
    Nov 11 at 17:21










  • Thank you for the response, how do I get the full traceback? is it the errors I get on the console?
    – Javier Heisecke
    Nov 11 at 17:38












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to append to a list to then persist data in my shelve db



I have a file "base_de_datos" where I have my lists
Then I have a file "gestionador" where I load or save data



# ___base_de_datos___
clientes =
asesores =
solicitudes =


My code works for clientes and asesores but keeps dying at solicitudes it gives me a KeyError



# _____gestionador_____
import shelve
import base_de_datos as bd

def cargar_datos():
'''carga los datos en listas para su uso'''
bd.clientes = cargar_lista("clientes", "Clientes")
bd.asesores = cargar_lista("asesores", "Asesores")
bd.solicitudes = cargar_lista("solicitudes", "Solicitudes")

def guardar_datos():
'''guarda los datos en las listas en archivos para la persistencia'''
guardar_lista(bd.clientes,"Clientes", "clientes")
guardar_lista(bd.asesores,"Asesores", "asesores")
guardar_lista(bd.solicitudes,"Solicitudes", "solicitudes")

def cargar_lista(clave, nombreArchivo):
'''carga los datos al sistema cuando se este ejecutando'''
try:
basededatos = shelve.open(nombreArchivo)
lista = basededatos[clave]

if lista is None:
lista =


return lista

except KeyError:
return print("ERROR Ocurrio un al encontrar los datos")

def guardar_lista(objeto,nombreArchivo, clave):
''' funcion que sirve para guardar los datos en basededatos'''
try:
basededatos = shelve.open(nombreArchivo,'n')
basededatos[clave] = objeto
except FileNotFoundError:
print("ERROR Archivo no existe")

else:
basededatos.close()
basededatos = None


This is how I call Solicitudes



def add_solicitud(self):
datos = Solicitud.promp_init()
solicitud = Solicitud(**datos)
base_de_datos.solicitudes.append(solicitud)
gestionador.guardar_datos()


My class Solicitudes, where I have the method promp_init()



class Boleta(metaclass=ABCMeta):
@abstractmethod
def __init__(self):
pass

class Solicitud(Boleta):
def __init__(self, date='' , cliente='', asesor=''):
super().__init__()
self.date= date
self.cliente = cliente
self.asesor = asesor

def promp_init():
date= datetime.now()
print("The date is the actual date")
cliente=input_entero()
asesor=input_entero()
return dict(
"date": date,
"cliente": cliente,
"asesor": asesor
)


I get the error once I finish typing Solicitud's data



'NoneType' object has no attribute 'append'


When I debug on pycharm I already get a KeyError when trying to open the file for Solicitudes at the the method cargar_lista I added



if lista is None:
lista =


because I was told I needed to initialize it first which it worked but after a while the same thing happened again



Edit: Somehow started working, I think It's an error that happens whenever I add a new list to "base_de_datos" and it needs to be initialize.










share|improve this question















I'm trying to append to a list to then persist data in my shelve db



I have a file "base_de_datos" where I have my lists
Then I have a file "gestionador" where I load or save data



# ___base_de_datos___
clientes =
asesores =
solicitudes =


My code works for clientes and asesores but keeps dying at solicitudes it gives me a KeyError



# _____gestionador_____
import shelve
import base_de_datos as bd

def cargar_datos():
'''carga los datos en listas para su uso'''
bd.clientes = cargar_lista("clientes", "Clientes")
bd.asesores = cargar_lista("asesores", "Asesores")
bd.solicitudes = cargar_lista("solicitudes", "Solicitudes")

def guardar_datos():
'''guarda los datos en las listas en archivos para la persistencia'''
guardar_lista(bd.clientes,"Clientes", "clientes")
guardar_lista(bd.asesores,"Asesores", "asesores")
guardar_lista(bd.solicitudes,"Solicitudes", "solicitudes")

def cargar_lista(clave, nombreArchivo):
'''carga los datos al sistema cuando se este ejecutando'''
try:
basededatos = shelve.open(nombreArchivo)
lista = basededatos[clave]

if lista is None:
lista =


return lista

except KeyError:
return print("ERROR Ocurrio un al encontrar los datos")

def guardar_lista(objeto,nombreArchivo, clave):
''' funcion que sirve para guardar los datos en basededatos'''
try:
basededatos = shelve.open(nombreArchivo,'n')
basededatos[clave] = objeto
except FileNotFoundError:
print("ERROR Archivo no existe")

else:
basededatos.close()
basededatos = None


This is how I call Solicitudes



def add_solicitud(self):
datos = Solicitud.promp_init()
solicitud = Solicitud(**datos)
base_de_datos.solicitudes.append(solicitud)
gestionador.guardar_datos()


My class Solicitudes, where I have the method promp_init()



class Boleta(metaclass=ABCMeta):
@abstractmethod
def __init__(self):
pass

class Solicitud(Boleta):
def __init__(self, date='' , cliente='', asesor=''):
super().__init__()
self.date= date
self.cliente = cliente
self.asesor = asesor

def promp_init():
date= datetime.now()
print("The date is the actual date")
cliente=input_entero()
asesor=input_entero()
return dict(
"date": date,
"cliente": cliente,
"asesor": asesor
)


I get the error once I finish typing Solicitud's data



'NoneType' object has no attribute 'append'


When I debug on pycharm I already get a KeyError when trying to open the file for Solicitudes at the the method cargar_lista I added



if lista is None:
lista =


because I was told I needed to initialize it first which it worked but after a while the same thing happened again



Edit: Somehow started working, I think It's an error that happens whenever I add a new list to "base_de_datos" and it needs to be initialize.







python-3.x persistence shelve






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 15:11

























asked Nov 11 at 17:15









Javier Heisecke

267




267











  • could you post the full stack trace of error?
    – Paritosh Singh
    Nov 11 at 17:19










  • Please include the full traceback, so we don't have to guess exactly what the context is.
    – Martijn Pieters
    Nov 11 at 17:21










  • Thank you for the response, how do I get the full traceback? is it the errors I get on the console?
    – Javier Heisecke
    Nov 11 at 17:38
















  • could you post the full stack trace of error?
    – Paritosh Singh
    Nov 11 at 17:19










  • Please include the full traceback, so we don't have to guess exactly what the context is.
    – Martijn Pieters
    Nov 11 at 17:21










  • Thank you for the response, how do I get the full traceback? is it the errors I get on the console?
    – Javier Heisecke
    Nov 11 at 17:38















could you post the full stack trace of error?
– Paritosh Singh
Nov 11 at 17:19




could you post the full stack trace of error?
– Paritosh Singh
Nov 11 at 17:19












Please include the full traceback, so we don't have to guess exactly what the context is.
– Martijn Pieters
Nov 11 at 17:21




Please include the full traceback, so we don't have to guess exactly what the context is.
– Martijn Pieters
Nov 11 at 17:21












Thank you for the response, how do I get the full traceback? is it the errors I get on the console?
– Javier Heisecke
Nov 11 at 17:38




Thank you for the response, how do I get the full traceback? is it the errors I get on the console?
– Javier Heisecke
Nov 11 at 17:38

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251194%2fshelve-giving-nonetype-error-even-though-its-there-python%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251194%2fshelve-giving-nonetype-error-even-though-its-there-python%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto