[Tutor] How to insert a variable into a pathname?

Patrick Thorstenson pthorstenson at co.montezuma.co.us
Tue Nov 9 18:05:56 CET 2004


Help. I am very new to python. I am trying to allow a user to create a
variable and then drop that variable into a file path name. It will then
run a command - in this case a copy/paste command. LIKE: I want to copy
parcel 5355 into the archives. 
 
The variable "VAR_Archive" is a 4 digit non-integer string such as 5355
or 5079. I want to insert it into both the input and output sides of the
command.
I want the final result to be:
Testfile = "F:/Parcels/Parcelshapefiles/p5355_test.shp"
Archive = "F:/Parcels/Aparcelarchives/p5355Archive.shp"
 
I have received copious amounts of great advice but I keep missing
something in the syntax(?). What I need is for somebody to spell out how
the file pathname should read. 
 
 
###
# Import system modules
import sys, string, os, win32com.client
 
# Create the Geoprocessor object
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
 
 
#this parameter selects the parcel to archive from the parameter window
in ArcGIS
VAR_Archive = sys.argv [1]
 
testfile = "F:/Parcels/ParcelShapefiles/p%s_test.shp" 
testfile % (VAR_Archive)
 
archfile = "F:/Parcels/Aparcelupdate/p%sArchive.shp"
archfile % (VAR_Archive)
 
# copy (input, output)
gp.copy_management(testfile, archfile)
###    
 
Thank you.
 
 
Patrick Thorstenson
GIS Specialist
Montezuma County
(970) 564-9298
pthorstenson at co.montezuma.co.us
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20041109/9e2197ca/attachment.htm


More information about the Tutor mailing list