Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

AttributeError: 'NoneType' object has no attribute 'filelist' #85

Open
leonatez opened this issue Aug 11, 2020 · 1 comment
Open

AttributeError: 'NoneType' object has no attribute 'filelist' #85

leonatez opened this issue Aug 11, 2020 · 1 comment

Comments

@leonatez
Copy link

I'm new to this module. I tried exactly your example but it says below exception:

Traceback (most recent call last):
File "/Users/mac/Downloads/BBEditRunTemp-test.py", line 6, in
document.write('output.docx')
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mailmerge.py", line 121, in write
for zi in self.zip.filelist:
AttributeError: 'NoneType' object has no attribute 'filelist'

The code is here:
from mailmerge import MailMerge
with MailMerge('input.docx') as document:
...
document.merge(field1='docx Mail Merge',
field2='Can be used for merging docx documents')
document.write('output.docx')

@ankit311
Copy link

ankit311 commented Mar 2, 2022

Instead of using with to open the existing document, use MailMerge function to read the file object.
To fix the error use the below code:

from mailmerge import MailMerge
document = MailMerge('input.docx')
document.merge(field1='docx Mail Merge', field2='Can be used for merging docx documents')
document.write('output.docx')

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants