1

I would like to create tool that will be generate *.csv with information about feature class (field_name, type). You can find my code:

import arcpy
import os
arcpy.env.overwriteOutput = True
dataset_name = arcpy.GetParameterAsText(0)
Report_folder = arcpy.GetParameterAsText(1)
fields = arcpy.ListFields()

for field in fields:
    print("{0} is a type of {1} with a length of {2}"
          .format(field.name, field.type, field.length))
      

enter image description here

Could you advise?

3
  • 1
    Apart from ListFields missing the dataset parameter, what is your question? – Berend Jan 26 at 9:44
  • Hi, thanks for your time. I now that I can put path for dataset, but I would like put here dataset_name as in script parameters. fields = arcpy.ListFields('dataset_name') - is it right, if I will put like this? – Anzhi Jan 26 at 10:17
  • Yes, but without the quotes: fields = arcpy.ListFields(dataset_name) – Berend Jan 26 at 10:45
0

This script solved my task:

import arcpy
import os
import xlwt
arcpy.env.overwriteOutput = True
Dataset_name = arcpy.GetParameterAsText(0)
Report_folder = arcpy.GetParameterAsText(1)
fields = arcpy.ListFields(Dataset_name)
wb = xlwt.Workbook() 
ws = wb.add_sheet('Test') 

ws.write(0, 0, "Field") 
ws.write(0, 1, "Type")
row = 1

for field in fields:
  print field.name, field.length, field.type
  ws.write(row, 0, field.name)
  ws.write(row, 1, field.type)
  row += 1
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.