Select to view content in your preferred language

python

1004
3
Jump to solution
03-24-2020 05:08 AM
KalSsin
Regular Contributor
Hi~~~~
This is the listfield. What did I do wrong?
import arcpy
featureclass = "C:\EsriTraining\ProVectorTiles\Create\SANDAG_Geology.gdb\Geology"
field_names = [f.name for f in arcpy.ListFields(featureclass)]
arcpy.featureclass = r"c:/data/municipal.gdb/hospitalsC:\EsriTraining\ProVectorTiles\Create\SANDAG_Geology.gdb\Geology"
field_names = [f.name for f in arcpy.ListFields(featureclass)]
arcpy.featureclass = r"C:\EsriTraining\ProVectorTiles\Create\SANDAG_Geology.gdb\Geology"
field_names = [f.name for f in arcpy.ListFields(featureclass)]
import arcpy
featureclass = r"C:\EsriTraining\ProVectorTiles\Create\SANDAG_Geology.gdb\Geology"
field_names = [f.name for f in arcpy.ListFields(featureclass
  File "<string>", line 4
    field_names = [f.name for f in arcpy.ListFields(featureclass
                                                               ^
SyntaxError: unexpected EOF while parsing
arcpy.featureclass = "C:\EsriTraining\ProVectorTiles\Create\SANDAG_Geology.gdb\Geology"
field_names = [f.name for f in arcpy.ListFields(featureclass)
  File "<string>", line 2
    field_names = [f.name for f in arcpy.ListFields(featureclass)
                                                                ^
SyntaxError: unexpected EOF while parsing
import arcpy
featureclass = r"C:\EsriTraining\ProVectorTiles\Create\SANDAG_Geology.gdb\Geology"
field_names = [f.name for f in arcpy.ListFields(featureclass)}
  File "<string>", line 4
    field_names = [f.name for f in arcpy.ListFields(featureclass)}
                                                                 ^
SyntaxError: invalid syntax
import arcpy
featureclass = r"C:\EsriTraining\ProVectorTiles\Create\SANDAG_Geology.gdb\Geology"
field_names = [f.name for f in arcpy.ListFields}
  File "<string>", line 4
    field_names = [f.name for f in arcpy.ListFields}
                                                   ^
SyntaxError: invalid syntax
0 Kudos
1 Solution

Accepted Solutions
DonShawEsri
Esri Contributor

A few things are going on here. In the last example, you ended the ListFields function with a } instead of starting it with a  (. You should try setting the work space for your data. The code below works for me (Python 3). Make sure you are using the correct version of Python for things like the print statement.

import arcpy

arcpy.env.workspace = 'C:/data/earthquakes.gdb'

feature_class = 'earthquake_points'

field_names = [f.name for f in arcpy.ListFields(feature_class)]

print(field_names)

					
				
			
			
				
			
			
				
			
			
				

View solution in original post

3 Replies
DanPatterson_Retired
MVP Emeritus

 [f.name for f in arcpy.ListFields]

[ must match ]  left and right brackets

DonShawEsri
Esri Contributor

A few things are going on here. In the last example, you ended the ListFields function with a } instead of starting it with a  (. You should try setting the work space for your data. The code below works for me (Python 3). Make sure you are using the correct version of Python for things like the print statement.

import arcpy

arcpy.env.workspace = 'C:/data/earthquakes.gdb'

feature_class = 'earthquake_points'

field_names = [f.name for f in arcpy.ListFields(feature_class)]

print(field_names)

					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
KalSsin
Regular Contributor

Thank you for your kind example.
I finally made it.

0 Kudos