I have some shapefiles to convert into KML file with a specific legend icon. So I tried to rearrange symbology and convert those shapefiles into .lyr files. After that, I put those files into a folder and used the following Python script.

import arcpy

arcpy.env.workspace = "E:/Layers"

# Set Local Variables
composite = 'NO_COMPOSITE'
pixels = 2048
dpi = 96

# Use the ListFiles method to identify all lyr and lyrx files in workspace
layers = arcpy.ListFiles("*.lyr*") 

if len(layers) > 0:
    for layer in layers:        
        # Strips the '.lyr(x)' part of the name and appends '.kmz'
        outKML = os.path.join(os.path.splitext(layer), ".kmz")
        for scale in range(10000):
            # Execute LayerToKML
            arcpy.LayerToKML_conversion(layer, outKML, scale, composite, 
                                        '', pixels, dpi, clamped)
    arcpy.AddMessage('There are no layer files in {}'.format(arcpy.env.workspace))

Which is a built-in code from the pro.arcgis.com resource site. But unfortunately, the program is showing errors and does not produce any result. Error showed TypeError: can only concatenate tuple (not "str") to tuple

What am I doing wrong?

  • Is it your intention to create 10,000 KMZ files? range(10000) will return a list with values ranging from 0 to 9999.
    – Hornbydd
    Commented Jan 24, 2021 at 20:11
  • First of all thanks a lot. No, I want to create kml files on a 1:10000 scale. from the tool description, I understand that if I put a number it will recognize it as a scale.
    – Jobaied
    Commented Jan 24, 2021 at 20:18

1 Answer 1


The splitext splits the path into the root and the extension (https://docs.python.org/3/library/os.path.html#os.path.splitext). So the return value is a tuple. You probably want to choose the root. Therefore, you need to change the line in your code as follows

outKML = os.path.join(os.path.splitext(layer)[0], ".kmz")
  • Thank You, It seems working
    – Jobaied
    Commented Jan 25, 2021 at 6:57
  • Please accept my answer if it works now @Jobaied
    – Nil
    Commented Jan 25, 2021 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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