Glen Elkins
Glen Elkins

Reputation: 917

Python keyword can't be an expression

Sorry for the basic question, the first time I've used python as I need it for something specific.

I'm using the docx-mailmerge 0.5.0 library which works great for replacing mailmerge tags in word.

However, some of the tags in word are like this test_Tag[1,1,0,0].

It appears as though the full string has to be used to replace the tag, so I can't use "test_Tag" I have to use "test_Tag[1,1,0,0]" the problem is the library works like this to merge the fields:

document.merge(
    mergeFieldName = "Value To Replace With"
)

so if the field was just "test_Tag":

document.merge(
    test_Tag = "Value To Replace With"
)

works fine, but I can't use :

document.merge(
    test_Tag[1,1,0,0] = "Value To Replace With"
)

Which is obvious! I get "keyword can't be an expression" - so how would i go about doing this? I need to be able to push through the tag names in a loop from an array.

Upvotes: 1

Views: 109

Answers (1)

juanpa.arrivillaga
juanpa.arrivillaga

Reputation: 96236

The following is ugly, but it should work:

document.merge(
    **{"test_Tag[1,1,0,0]":"Value To Replace With"}
)

Upvotes: 3

Related Questions