Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a script that renames and copies files (feature classes) on an SDE connection. This script works just fine if the feature class name does not start with an 'S'. If the feature class name does start with an 'S', it gets removed. As you can see in the script below I use Python's lstrip to remove the 'SDE.' from the file name to rename it. The 'SDE.' gets added again automatically after copying. So a feature class named HAM would be renamed SDE.R_HAM_QC. If the feature class is named STREETS it get renamed to SDE.R_TREETS_QC. See how the first S in STREETS is removed? Does anyone have a possible solution? Thank you.

    #Import modules
    import arcpy, os, sys
    from arcpy import env
    arcpy.env.overwriteOutput = True

    #Set variables
    outWorkspace = "Database Connections\Connection to" 
    arcpy.env.workspace = outWorkspace 
    fileName = "SDE.STREETS"

    #Describe the file name
    desc = arcpy.Describe(fileName)

    if desc.datasetType == "FeatureClass":

          #Rename and copy data if it is a feature class        
          name1 = fileName.lstrip('SDE.')
          print name1
          newName = "R_" + name1 + "_QC"
          outFile = os.path.join(outWorkspace, newName)
          arcpy.Copy_management(fileName, outFile)
share|improve this question
up vote 1 down vote accepted

What about slicing off the 'SDE.' part instead?

>>> fc = 'SDE.whatever'
>>> fc[4:]
share|improve this answer
That was it! My files are getting renamed properly now. Thank you for the quick response, Chad. – Patty Jula Dec 21 '11 at 16:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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