Select to view content in your preferred language

How to Extract values from a field and write them to a text file using Python?

4208
12
Jump to solution
07-11-2013 10:06 AM
ChristiNelson1
Deactivated User
Hi all,

I am using ArcGIS 10.0 Python 2.6. I need to get the values from a single field (APN) out of a PARCEL feature class attribute table and write them to a text file.  The feature class contains about 20 different fields.  I only need to write the values from APN.

The only info I can find is outdated.  Can anyone help?

Thanks,
Christi Nelson
Tags (2)
0 Kudos
12 Replies
T__WayneWhitley
Honored Contributor
@Caleb, that's awesome!  ...and oh yeah, v10.

@Rhett, good to know!!  Interesting indeed, figured it would take longer, but that's much slower than I assumed.  Nice comparison!


Enjoy,
Wayne
0 Kudos
StacyRendall1
Frequent Contributor
Just for fun, while talking about efficiency, may as well make to as few lines as possible 🙂

import arcpy
fc = r'G:\Data\Geodatabase\Cedar_County.gdb\CADASTRAL\PARCEL'
output = r'C:\Users\GIS\Desktop\textfile.txt'

with open(output, 'w') as f:
    f.write('\n'.join(r.PID for r in arcpy.SearchCursor(fc)))
print 'Created "%s"' %output


@ Wayne, I didn't mention the da module because she mentioned she was on version 10.0 still...but as Chris said, the new .da cursors are waaaay faster!

P.S. I need to limit my sugar intake while at work, feeling loopy...Happy scripting!


If only I could +10 you for using join()!
0 Kudos
RhettZufelt
MVP Notable Contributor
If only I could +10 you for using join()!


Well, I can only give you one for it, but done....

R_
0 Kudos