I try to replace part of text in 23 mxd files from "d" into 'map num: '. The code run without errors, but the result in the maps is only the character "m" instead of 'map num: ' I run this code:
import arcpy
from arcpy import env
env.workspace = r"G:\PROJECTS\road70-75"
counter = 0
for mxdname in arcpy.ListFiles("*.mxd"):
print mxdname
mxd = arcpy.mapping.MapDocument(
r"G:\PROJECTS\road70-75\\" + mxdname)
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if elm.text.startswith(u'd'):
elm.text = elm.text.replace(u'd', u'map num: ')[0]
print 'elm.text','\n'
counter = counter + 1
mxd.save()
del mxd
print 'total maps: ', counter
[0]. You are slicing'map num:'and only keeping first char which is m