I'm having trouble finding a way to write the output of a SearchCursor function to a txt. file. I can print it just fine in a format that is desirable. I just don't know how to get from there to a txt. file. Here's my code below:
import arcpyfrom arcpy import envenv.workspace = "G:\Geocomputation_Project\Section C\Lin_Ref_test"shape = "Points.shp"cursor = arcpy.SearchCursor(shape)f = open("test_field.txt", "w")for row in cursor: print (row.getValue("ITEMID")),(row.getValue("New_X_LRR")), (row.getValue("New_Y_LRR")) print "done"The txt file does not yet exist. When I start running this script, I hope to be able to overwrite the text file as I do more iterations. I can just stay with "w" function, right? Also, do I need a complete path of where I want the txt. file to be created or does it assume the initial workspace stated earlier in the script?
P.S. using ArcMap 10.2.2
أكثر...
import arcpyfrom arcpy import envenv.workspace = "G:\Geocomputation_Project\Section C\Lin_Ref_test"shape = "Points.shp"cursor = arcpy.SearchCursor(shape)f = open("test_field.txt", "w")for row in cursor: print (row.getValue("ITEMID")),(row.getValue("New_X_LRR")), (row.getValue("New_Y_LRR")) print "done"The txt file does not yet exist. When I start running this script, I hope to be able to overwrite the text file as I do more iterations. I can just stay with "w" function, right? Also, do I need a complete path of where I want the txt. file to be created or does it assume the initial workspace stated earlier in the script?
P.S. using ArcMap 10.2.2
أكثر...