[python-win32] Displaying contents of a file using PyWin

Mark Hammond mhammond at skippinet.com.au
Thu Dec 21 22:28:13 EST 2006


Hi Gabriel,

> [Forwarded from python-list at ...]
>
> At Thursday 21/12/2006 13:51, MiguelS wrote:
>
> >import win32ui
> >from pywin.mfc import docview
> >
> >t = docview.DocTemplate()
> >t.OpenDocumentFile("d:/temp/music.log", True)
> >
> >This caused windows to close PythonWin.
>
> This appears to be a problem with pywin32.
> Using release 209 for Python 2.4 I get an Access Violation.

It was attempting to set a Python error without the GIL held.  I've fixed
that - it now results in:

win32ui: PyCDocument::OnOpenDocument handler does not exist.
>>>

Using:

>>> t.OpenDocumentFile(None)

Opens a document - I'm afraid I can't recall the MFC semantics here at the
moment.

> Also I've noticed that this idiom:
>
> try:
>      win32ui.GetApp().RemoveDocTemplate(template)
> except NameError:
>      # haven't run this before - that's ok
>      pass
>
> doesn't work anymore because RemoveDocTemplate raises a different
> exception now.

I can't recall any change I made that would account for that.  I'm assuming
that the NameError comes from 'template' which is yet to be assigned - but
in that case RemoveDocTemplate should not be called as the NameError happens
before.  I don't recall (and grep doesn't show) that pythonwin ever raises
this exception.

Mark




More information about the Python-list mailing list