Can I create DBF object from a file handle

82 views
Skip to first unread message

Travis Dart

unread,
Apr 1, 2015, 4:36:16 PM4/1/15
to python...@googlegroups.com
It appears that DBF objects must be created by passing in the file path. Is it possible to create a DBF object with a file handle?

This would have a few advantages:
It would behave more like Python's csv module
You could use the existing file context manager instead of having to write a new one for the DBF module
You could operate on StringIO objects

Ideally, I'm looking for something like this:

with open(dbf_file_path) as fileHandle:
theDBF = dbf.Table(fileHandle)
doStuffWith(theDBF)

Ethan Furman

unread,
Apr 1, 2015, 5:30:45 PM4/1/15
to python...@googlegroups.com
dbf.Table already supports the context-manager protocol, so you can do:

with dbf.Table(dbf_file_path) as theDBF:
doStuffWith(theDBF)

and also:

theDBF = dbf.Table(dbf_file_Path)
with theDBF:
doStuffWith(theDBF)

What advantages are offered by being able to work on StringIO objects?

--
~Ethan~
Reply all
Reply to author
Forward
0 new messages