For this CSV file, simple-csv.csv:
34.79038,-96.80871,"4/13/1983"
34.93032,-96.44490,"2/5/1967"
34.95507,-96.92268,"12/23/2001"
34.95689,-96.92263,"8/9/1999"
34.92559,-96.68021,"8/25/1954"
This code will open it up and print it out:
>>> # import csv module
>>> import csv
>>> # open and read the csv file into memory
>>> file = open(‘C:/testing/simple-csv.csv’)
>>> reader = csv.reader(file)
>>> # iterate through the lines and print them to stdout
>>> # the csv module returns us a list of lists and we
>>> # simply iterate through it
>>> for line in reader:
... print line
...
[‘34.79038’, ‘-96.80871’, ‘4/13/1983’]
[‘34.93032’, ‘-96.44490’, ‘2/5/1967’]
[‘34.95507’, ‘-96.92268’, ‘12/23/2001’]
[‘34.95689’, ‘-96.92263’, ‘8/9/1999’]
[‘34.92559’, ‘-96.68021’, ‘8/25/1954’]
If you wanted to only get the first and second columns, do something like:
for line in reader:
print line[0], line[1]
Why not something like this:
import arcpy
from arcpy import env
import csv
import os
env.workspace = ("WORKSPACE")
fcList = arcpy.ListFeatureClasses()
with open('codes.csv', 'wb') as f:
writer = csv.writer(f)
writer.writerows(fcList)
Best Answer
I would use
random.choice()
to make a random selection from the .csv file and insert that into your FC rows using an Update Cursor.