Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8403917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:27:45+00:00 2026-06-09T22:27:45+00:00

I am using the python library docx: http://github.com/mikemaccana/python-docx My goal is to open a

  • 0

I am using the python library docx: http://github.com/mikemaccana/python-docx

My goal is to open a file, replace certain words, then write the file with replacement.

My current code:

#! /usr/bin/python

from docx import *

openDoc = "test.docx"
writeDoc = "test2.docx"
replace = {"Test":"TEST"}

document = opendocx(openDoc)
docbody = document.xpath('/w:document/w:body', namespaces=nsprefixes)[0]

print getdocumenttext(document)

for key in replace:
    if search(docbody, key):
        print "Found" , key , "replacing with" , replace[key]
        docbody = replace(docbody,key,replace[key])

print getdocumenttext(document)

# ideally just want to mirror current document details here..
relationships = relationshiplist()
coreprops = coreproperties(title='',subject='',creator='',keywords=[])

savedocx(document,coreprops,appproperties(),contenttypes(),websettings(),wordrelationships(relationships),'a.docx')

`
However I get the following error:

Traceback (most recent call last):
  File "process.py", line 17, in <module>
    docbody = replace(docbody,key,replace[key])
TypeError: 'dict' object is not callable

I have no idea why this is happening, but I think it has something to do with the docx module. Can anyone explain why this is happening?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:27:45+00:00Added an answer on June 9, 2026 at 10:27 pm

    You assigned replace to a dictionary at the very top:

    replace = {"Test":"TEST"}

    So you cannot use the replace() method, because the word replace is now pointing to a dictionary – instead of what I suspect is some method from your library.

    Rename your dictionary and it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Python's AWeber API (https://github.com/aweber/AWeber-API-Python-Library), and I frequently get these exceptions. I
I'm using the python-openid library from Janrain at http://openidenabled.com/python-openid/ I adapted their Django example
I'm using a open-source Python library in my project. This library logs a lot
I am using Python's elementtree library to parse an .XML file that I exported
I am making several http requests to a particular host using python's urllib2 library.
How can I send custom HTTP Headers using python xmlrpclib library ! ? I
Using the python library openpyxl I am reading an XLSX file created in excel
Using Python's Imaging Library I want to create a PNG file. I would like
I am attempting to get synonyms for a word using the python library NLTK.
I'm using Python's suds library which tries to fetch xml.xsd over the network. Unfortunately,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.