diff options
| author | tusharmakkar08 <tusharmakkar08@gmail.com> | 2016-02-22 16:36:26 +0530 |
|---|---|---|
| committer | tusharmakkar08 <tusharmakkar08@gmail.com> | 2016-02-22 16:36:26 +0530 |
| commit | d515724817111d9dc60db15e1b54e149f807fba1 (patch) | |
| tree | de507ff397ddd44458e1cde114d839eaf0e208ab /tablib/packages/dbfpy3 | |
| parent | 2814fbc38100e00b2e78d47cb05defa8e9854126 (diff) | |
| download | tablib-d515724817111d9dc60db15e1b54e149f807fba1.tar.gz | |
PEP-8 standards followed
Diffstat (limited to 'tablib/packages/dbfpy3')
| -rw-r--r-- | tablib/packages/dbfpy3/dbf.py | 43 | ||||
| -rw-r--r-- | tablib/packages/dbfpy3/dbfnew.py | 29 |
2 files changed, 39 insertions, 33 deletions
diff --git a/tablib/packages/dbfpy3/dbf.py b/tablib/packages/dbfpy3/dbf.py index 42de8a4..6fee457 100644 --- a/tablib/packages/dbfpy3/dbf.py +++ b/tablib/packages/dbfpy3/dbf.py @@ -66,6 +66,7 @@ from . import header from . import record from .utils import INVALID_VALUE + class Dbf(object): """DBF accessor. @@ -82,13 +83,13 @@ class Dbf(object): """ __slots__ = ("name", "header", "stream", - "_changed", "_new", "_ignore_errors") + "_changed", "_new", "_ignore_errors") HeaderClass = header.DbfHeader RecordClass = record.DbfRecord INVALID_VALUE = INVALID_VALUE - ## initialization and creation helpers + # initialization and creation helpers def __init__(self, f, readOnly=False, new=False, ignoreErrors=False): """Initialize instance. @@ -137,7 +138,7 @@ class Dbf(object): self._new = bool(new) self._changed = False - ## properties + # properties closed = property(lambda self: self.stream.closed) recordCount = property(lambda self: self.header.recordCount) @@ -149,6 +150,7 @@ class Dbf(object): def ignoreErrors(self, value): """Update `ignoreErrors` flag on the header object and self""" self.header.ignoreErrors = self._ignore_errors = bool(value) + ignoreErrors = property( lambda self: self._ignore_errors, ignoreErrors, @@ -159,7 +161,7 @@ class Dbf(object): """) - ## protected methods + # protected methods def _fixIndex(self, index): """Return fixed index. @@ -185,7 +187,7 @@ class Dbf(object): raise IndexError("Record index out of range") return index - ## iterface methods + # iterface methods def close(self): self.flush() @@ -227,9 +229,9 @@ class Dbf(object): self.header.addField(*defs) else: raise TypeError("At least one record was added, " - "structure can't be changed") + "structure can't be changed") - ## 'magic' methods (representation and sequence interface) + # 'magic' methods (representation and sequence interface) def __repr__(self): return "Dbf stream '%s'\n" % self.stream + repr(self.header) @@ -249,19 +251,20 @@ class Dbf(object): self._changed = True self._new = False - #def __del__(self): - # """Flush stream upon deletion of the object.""" - # self.flush() + # def __del__(self): + # """Flush stream upon deletion of the object.""" + # self.flush() -def demoRead(filename): +def demo_read(filename): _dbf = Dbf(filename, True) for _rec in _dbf: print() print(repr(_rec)) _dbf.close() -def demoCreate(filename): + +def demo_create(filename): _dbf = Dbf(filename, new=True) _dbf.addField( ("NAME", "C", 15), @@ -270,10 +273,10 @@ def demoCreate(filename): ("BIRTHDATE", "D"), ) for (_n, _s, _i, _b) in ( - ("John", "Miller", "YC", (1981, 1, 2)), - ("Andy", "Larkin", "AL", (1982, 3, 4)), - ("Bill", "Clinth", "", (1983, 5, 6)), - ("Bobb", "McNail", "", (1984, 7, 8)), + ("John", "Miller", "YC", (1981, 1, 2)), + ("Andy", "Larkin", "AL", (1982, 3, 4)), + ("Bill", "Clinth", "", (1983, 5, 6)), + ("Bobb", "McNail", "", (1984, 7, 8)), ): _rec = _dbf.newRecord() _rec["NAME"] = _n @@ -284,10 +287,12 @@ def demoCreate(filename): print(repr(_dbf)) _dbf.close() -if (__name__=='__main__'): + +if __name__ == '__main__': import sys + _name = len(sys.argv) > 1 and sys.argv[1] or "county.dbf" - demoCreate(_name) - demoRead(_name) + demo_create(_name) + demo_read(_name) # vim: set et sw=4 sts=4 : diff --git a/tablib/packages/dbfpy3/dbfnew.py b/tablib/packages/dbfpy3/dbfnew.py index 4051bc6..8fab275 100644 --- a/tablib/packages/dbfpy3/dbfnew.py +++ b/tablib/packages/dbfpy3/dbfnew.py @@ -29,6 +29,7 @@ from .fields import * from .header import * from .record import * + class _FieldDefinition(object): """Field definition. @@ -145,28 +146,28 @@ class dbf_new(object): _dbfStream.close() -if (__name__=='__main__'): +if __name__ == '__main__': # create a new DBF-File - dbfn=dbf_new() - dbfn.add_field("name",'C',80) - dbfn.add_field("price",'N',10,2) - dbfn.add_field("date",'D',8) + dbfn = dbf_new() + dbfn.add_field("name", 'C', 80) + dbfn.add_field("price", 'N', 10, 2) + dbfn.add_field("date", 'D', 8) dbfn.write("tst.dbf") # test new dbf print("*** created tst.dbf: ***") dbft = Dbf('tst.dbf', readOnly=0) print(repr(dbft)) # add a record - rec=DbfRecord(dbft) - rec['name']='something' - rec['price']=10.5 - rec['date']=(2000,1,12) + rec = DbfRecord(dbft) + rec['name'] = 'something' + rec['price'] = 10.5 + rec['date'] = (2000, 1, 12) rec.store() # add another record - rec=DbfRecord(dbft) - rec['name']='foo and bar' - rec['price']=12234 - rec['date']=(1992,7,15) + rec = DbfRecord(dbft) + rec['name'] = 'foo and bar' + rec['price'] = 12234 + rec['date'] = (1992, 7, 15) rec.store() # show the records @@ -175,7 +176,7 @@ if (__name__=='__main__'): for i1 in range(len(dbft)): rec = dbft[i1] for fldName in dbft.fieldNames: - print('%s:\t %s'%(fldName, rec[fldName])) + print('%s:\t %s' % (fldName, rec[fldName])) print() dbft.close() |
