代码语言:javascript复制
import arcpy
from arcpy import env
import os
import types
fc = 'D:/demo.gdb/test' # file location .
fields = ["Id", "name", "descr"] # you table columuns .
print ' '
with arcpy.da.SearchCursor(fc, fields) as cursor:
f = file('D:/demo.txt', 'w') # open for 'w'riting
for row in cursor:
str = "{0}, {1}, {2}".format(row[0], row[1], row[2])
#print("{0}, {1}, {2}".format(row[0], row[1], row[2]))
print 'The contents is :',str
f.write(str) # write text to file
f.write('n');
# close the file
f.close()
#print out the content of this text.
f = file('D:/demo.txt')
# if no mode is specified, 'r'ead mode is assumed by default
while True:
line = f.readline()
if len(line) == 0: # Zero length indicates EOF
break
print line,
# Notice comma to avoid automatic newline added by Python
f.close() # close the file