2012-12-19 5 views
1

파이썬 초보자는 여기 있으니 부드럽게하십시오.파이썬에서 dbf를 csv로 변환하려고 할 때 오류가 발생했습니다.

dbf 파일을 csv로 변환하려고합니다. 나는 previous, similar 질문 (반대 변환으로)을 우연히 만났고, dbf 모듈을 사용하여 abou를 생각하고 있었다.

Traceback (most recent call last): 
    File "<pyshell#24>", line 1, in <module> 
    in_db.export(filename=csv_fn, header=True) 
    File "C:\Python27\ArcGIS10.1\lib\site-packages\dbf.py", line 3379, in __getattr__ 
    return object.__getattribute__(self, name) 
AttributeError: 'Db3Table' object has no attribute 'export' 

왜 내보내기가 실패하는 : 나는 다음과 같은 오류 얻을 그것을 실행하려고하면

import dbf 

dbf_fn = r'_PATH_HERE_\dbffile.dbf' 
csv_fn = r'_PATH_HERE_\csvfile.csv' 

in_db = dbf.Table(dbf_fn) 

in_db.export(filename=csv_fn, header=True) 

:

이 코드를 시도 docs에서 예제를 사용하여?


는 업데이트 : chm에 의해 제안

는 지금 사용

dbf.export(in_db, csv_fn, header=True) 

를이 여전히 문제가 발생합니다

Traceback (most recent call last): 
    File "D:\Data_RP\data\projects\kN\GIS\python\04_convert_dbf_ALT.py", line 31, in <module> 
    dbf.export(in_db, filename=csv_fn, header=True) 
    File "C:\Python27\ArcGIS10.1\lib\site-packages\dbf.py", line 5670, in export 
    table = source_table(table_or_records[0]) 
    File "C:\Python27\ArcGIS10.1\lib\site-packages\dbf.py", line 3384, in __getitem__ 
    return self._table[value] 
    File "C:\Python27\ArcGIS10.1\lib\site-packages\dbf.py", line 3175, in __getitem__ 
    raise DbfError("%s is closed; record %d is unavailable" % (meta.filename, index)) 
DbfError: D:\Data_RP\data\projects\kN\GIS\shapes\SWM_4N.dbf is closed; record 0 is unavailable 

답변

4

내가 찾아 그 사이트의 문서 잘못된 것입니다. 코드에서 도움말을 사용하면 아래 우측 문서 :

export(table_or_records, filename, field_names=None, 
format='csv', header=True, codepage=None) 
writes the records using CSV or tab-delimited format, using the filename 
given if specified, otherwise the table name 
if table_or_records is a collection of records (not an actual table) they 
should all be of the same format 

1. export 이제 클래스 Table의 구성원이 아닙니다. 그냥 후 (코드 샘플 :

import dbf 

csv_fn = r'sdv.csv' 

table = dbf.Table('temptable.dbf') 
table.open() 

dat=('John Doe', 31) 
table.append(dat) 
dbf.export(table, csv_fn, header = True) 
+0

감사 테이블을 생성 open 구석 구석 dbf.export(in_db, csv_fn, header=True) 대신 in_db.export(filename=csv_fn, header=True)

의 사용합니다. 나는 너의 제안을 사용했다. 불행히도 DbfError : D : \ Data_RP \ data \ projects \ kN \ GIS \ shapes \ SWM_4N.dbf가 닫히고 다른 문제가 발생했습니다. 레코드 0을 사용할 수 없습니다 '. 지금 문제는 무엇입니까? o_O – radek

+1

죄송합니다, 뭔가를 잊었습니다, 저의 최신 답변을 읽어보십시오. – prehistoricpenguin

+0

Ach - 너무 간단합니다. 업데이트 해 주셔서 감사합니다. 모든 작업이 완료되었습니다. – radek

관련 문제