PEATDB/Sandbox.py
def importDict(self, importdata, namefield='name', overwrite=True):
        """Import list of dicts, each one is a record"""
        if len(importdata) == 0:
            return
        
        fields = importdata[0].keys()
        if not namefield in fields or not 'name' in fields:
            print 'no such field for keyname field'
            namefield = fields[0]
            #return
        fields.remove(namefield)
        for f in fields:
            self.addField(f, 'text')
        for d in importdata:
            name = d[namefield]
            self.add(name)
            for f in fields:
                self.data[name][f] = d[f]        
        #print self
        return
Import list of dicts, each one is a record
Import list of dicts, each one is a record
Import list of dicts each one is a record
def importDict(self, importdata, namefield='name', overwrite=True):
        if len(importdata) == 0:
            return
        fields = importdata[0].keys()
        if not namefield in fields or not 'name' in fields:
            print 'no such field for keyname field'
            namefield = fields[0]
        fields.remove(namefield)
        for f in fields:
            self.addField(f, 'text')
        for d in importdata:
            name = d[namefield]
            self.add(name)
            for f in fields:
                self.data[name][f] = d[f]        
        return
def importDict ( self , importdata , namefield = 'name' , overwrite = True ) : if len ( importdata ) == 0 : return fields = importdata [ 0 ] . keys ( ) if not namefield in fields or not 'name' in fields : print 'no such field for keyname field' namefield = fields [ 0 ] fields . remove ( namefield ) for f in fields : self . addField ( f , 'text' ) for d in importdata : name = d [ namefield ] self . add ( name ) for f in fields : self . data [ name ] [ f ] = d [ f ] return
Import list of dicts, each one is a record
Import list of dicts each one is a record
"""Import list of dicts, each one is a record""" #return #print self
self
importdata
namefield
overwrite