This question already has an answer here:

I am working on an application and I am a beginner in Python :(

I want to add a shapefile, the execution is successful and everything but no result appears on ArcMap, here is the code I use:

import arcpy


    mxd = arcpy.mapping.MapDocument("CURRENT")

    df = arcpy.mapping.ListDataFrames(mxd)[0]

    newlayer1 = arcpy.mapping.Layer(E:\DATA SF\SFcircuit\shape_zizo\batiment.shp")
    print newlayer1
    arcpy.mapping.AddLayer(df, newlayer1, "TOP")  


    # save the map to persist the added layer

except Exception as ex:
    print ex.args[0]

marked as duplicate by PolyGeo Oct 11 '15 at 8:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


I think this line:

newlayer1 = arcpy.mapping.Layer(E:\DATA SF\SFcircuit\shape_zizo\batiment.shp")

needs to be:

newlayer1 = arcpy.mapping.Layer(r"E:\DATA SF\SFcircuit\shape_zizo\batiment.shp")

As commented by @Llaves:

r indicates a raw string literal. Without the r, the backslash \ indicates an escape sequence, such as a newline.


Just run MakeFeatureLayer in the Python window:

mxd = arcpy.mapping.MapDocument("current")
arcpy.management.MakeFeatureLayer_management(r"E:\DATA SF\SFcircuit\shape_zizo\batiment.shp", "batiment")

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