Hi,
Is there a function that returns the name of the variable rather than its contents.
For example.
T = 1
R= 2
S= 3
P = (T, R, S)
Is there a fucntion that if I do function(T) it will return T?
Please see Posting Code blocks in the new GeoNet
Suggested change, use a list, and create a list of labels in the same order:
Transmission = [T330OH, T330UG, T220OV, T132OH, T132UG, T66OV, T66UG, T33OH, T33UG, TransStruc, Substation] TransLabels = ["T330OH", "T330UG", "T220OV", "T132OH" (etc)
Then at the end:
k = 0 for Struc in Transmission: outputPath = r"S:\SupportServices\LGAShapefiles" basefileName = str(LGA2)+str(Struc)) fileFormat= '.shp' finalDest = os.path.join(outputPath,basefileName+Translabels + fileFormat) arcpy.Clip_analysis(Struc,"LGAlyr", finalDest) k += 1 print "Process ended"
An unrelated comment, you seem to be using ListFeatureClasses (which returns a list) when you really want a path to a single dataset:
maybe instead of
T330OH = arcpy.ListFeatureClasses("GISTRAN.Trans_330kV_OH_Carrier","All","GISTRAN.Transmission")
you mean:
T330OH = os.path.join("GISTRAN.Transmission", "GISTRAN.Trans_330kV_OH_Carrier")
import arcpyimport sysimport os
# Script to create LGA Map with WP Infrastructure
# Define variables
arcpy.env.workspace = r"C:\Users\N041871\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\DynamicCredentials@GISR.sde"arcpy.env.overwriteOutput = True#LGA = arcpy.GetParameterAsText(0) # Input Required Local Government AreaLGA ="COOROW, SHIRE OF"LGA2 = "COOROW"
#Define Layers to Intersect
#1. Transmission LayersT330OH = arcpy.ListFeatureClasses("GISTRAN.Trans_330kV_OH_Carrier","All","GISTRAN.Transmission")T330UG = arcpy.ListFeatureClasses("GISTRAN.Trans_330kV_UG_Cable","All","GISTRAN.Transmission")T220OV = arcpy.ListFeatureClasses("GISTRAN.Trans_220kV_OH_Carrier","All","GISTRAN.Transmission")T132OH = r"C:\Users\N041871\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\DynamicCredentials@GISR.sde\GISTRAN.Transmission\GISTRAN.Trans_132kV_OH_Carrier"T132UG = arcpy.ListFeatureClasses("GISTRAN.Trans_132kV_UG_Cable","All","GISTRAN.Transmission")T66OV = arcpy.ListFeatureClasses("GISTRAN.Trans_66kV_OH_Carrier","All","GISTRAN.Transmission")T66UG = arcpy.ListFeatureClasses("GISTRAN.Trans_66kV_UG_Cable","All","GISTRAN.Transmission")T33OH = arcpy.ListFeatureClasses("GISTRAN.Trans_33kV_OH_Carrier","All","GISTRAN.Transmission")T33UG = arcpy.ListFeatureClasses("GISTRAN.Trans_33kV_UG_Cable","All","GISTRAN.Transmission")TransStruc = arcpy.ListFeatureClasses("GISTRAN.Trans_Structure","All","GISTRAN.Transmission")Substation = arcpy.ListFeatureClasses("GISTRAN.Substation","All","GISTRAN.Transmission")#Group Transmission Values:Transmission = (T330OH, T330UG, T220OV, T132OH, T132UG, T66OV, T66UG, T33OH, T33UG, TransStruc, Substation) #Select Required LGAarcpy.MakeFeatureLayer_management("GISEXT.Local_Government_Authority", "LGAlyr")fieldName = "NAME"Query = "\""+fieldName+"\"='"+LGA+"'"arcpy.SelectLayerByAttribute_management ("LGAlyr", "NEW_SELECTION", Query)###arcpy.SelectLayerByAttribute_management ("LGAlyr", "NEW_SELECTION", """ "NAME" = 'ALBANY, CITY OF' """) - working code
for Struc in Transmission:outputPath = r"S:\SupportServices\LGAShapefiles"basefileName = str(LGA2)+str(Struc))fileFormat= '.shp'finalDest = os.path.join(outputPath,basefileName+fileFormat)#print Struc
arcpy.Clip_analysis(T132OH, "LGAlyr",finalDest)#arcpy.Clip_analysis(Struc,"LGAlyr", finalDest)
print "Process ended"
That is my code.
In the last loop I want to use the variable name to name the output file and the variable content for geoprocessing....
Is that possible?
You could create another list:
P1 = ["T","R","S"]
filename = "XYZ" + P1[0]
Or maybe a dictionary?
D = {1:"T", 2: "R", 3: "S"}
D[1] is "T"
if T == 1, D is "T"
I want to loop through P and then return T R S, not 1 2 3
e.g
for x in P
filename = " XYZ " + T
The desired output is XYZT not XYZ1
Can you explain what you are trying to do?
What do you do after P = (T,R,S)?
P[0] and P[T-1] will both return 1.
eval("T") will also return 1.
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.