Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

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 title "Text that remains Proposed Thing to replace"

var_a = New Text

I want the output to be

"Text that remains Proposed New text"

Currently outputs this

"(u'Text that remains ', u'Proposed', u' Thing to replace')"

Trying to add the var_a

b = a.partition('Proposed') + var_a

But get this error

: can only concatenate tuple (not "str") to tuple Failed to execute (LegendText).

# Loop through each text element in the map document
for textElement in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):

# Replace Title text
if == "Title":

# With this text
a = textElement.text
b = a.partition('Proposed')
textElement.text = str(b)

Any ideas?

share|improve this question

closed as off topic by blah238, Devdatta Tengshe, whuber Feb 25 '13 at 14:53

Questions on Geographic Information Systems Stack Exchange are expected to relate to geographic information systems within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

str.partition returns a tuple, not a string. I think that's what's holding you up. – blah238 May 15 '12 at 22:33
How can I convert it back into a string without it looking like this? "(u'Text that remains ', u'Proposed', u' Thing to replace')" – Tristan Forward May 15 '12 at 22:37
You don't want to convert the tuple to a string, you want to access the meaningful part of the tuple (the 3rd element), and replace that substring in the original string with the new string. If that makes any sense. – blah238 May 15 '12 at 22:47
up vote 3 down vote accepted

Try something like this:

new = "new text"
text = textElement.text
old = text.partition('Proposed')[2] # Get the 3rd element of the tuple, the part after "Proposed"
textElement.text = text.replace(old, new)
share|improve this answer
Thanks that worked – Tristan Forward May 15 '12 at 22:47

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