Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 textElement.name == "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.

1  
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')" –  TForward May 15 '12 at 22:37
1  
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

1 Answer 1

up vote 2 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 –  TForward May 15 '12 at 22:47

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