Q:

Small error on claim.py def load():

I am having a load error on my claim.py when i reload claim.DB on my bot. This is the code:
def load():
    claimDB = {}
    data = open("claim.DB").read().split("\n")
    for a in data:
       if a.strip() != "":
          claimDB[a.split(",")[0]] = a.split(",")[1:]
    claim.claimDB = claimDB

After it reloads it causes this:
    {'charles': []}  This is the correct way it should be.
To turn into this after the reload:
    {'charles': ['']} This is not the correct way.
Which it's not suppose to do. I'm not really sure how to fix it so that doesn't happen.

A:

Assuming that the claimDB is a list:
def load():
    claimDB = {}
    data = open("claim.DB").read().split("\n")
    for a in data:
       aslist = a.split(",")
       if len(aslist) ==  0:
          pass # Blank Line so skip
       else
          claimDB[data[0]] = [a.strip() for a in data[1:] if len(a)]

# Claim(s) N.B. if aslist = ['something',] then aslist[1:] = []
    claim.claimDB = claimDB

Of course if your claimDB is only access through your code you could save all the trouble reading & writing it by changing save and load to:
import pickle

def save(claim):
   """ Save between sessions """
   with outfile = open('saveclaims.db' 'wb'):
      pickle.dump(outfile, claim.claimDB)
   finally:
      outfile.flush()
      outfile.close()

def load(claim):
   """ Load saved between sessions """
   with infile = open('saveclaims.db' 'rb'):
      claim.claimDB = pickle.dump(infile)
   finally:
      infile.close()

