从DBF转换时,我试图使字段名称的字符数限制在10个字符左右。我尝试了好几种不同的库(dbf和dbfimport),但是没有运气。我不确定是否有可能。
示例:
Original
Field 1 = percentage
Field 2 = percentage_all
Converts to
Field 1 = percentage
Field 2 = percentag2
代码:
import dbf
import os, sys, collections
reload(sys)
sys.setdefaultencoding('utf-8')
path = r""
for dirpath, subdirs, files in os.walk(path):
for file in files:
if file.endswith(('.dbf', '.DBF')):
dbflocation = os.path.abspath(os.path.join(dirpath, file)).lower()
print dbflocation
try:
tbl = dbf.structure(dbflocation)
print tbl
for field in tbl:
print field
except Exception, e:
print Exception
print e
continue