[python-win32] Boolean type changed in Python 3.0?

Sunny Carter Sunny.Carter at metaswitch.com
Mon Jan 4 17:51:42 CET 2010


Hi all,

I'm trying my posting again with a different subject so that it is more generic.

I am having problems calling across the win32 API using a Boolean argument in Python 3.0 (False in my python script) which is not recognised as a Boolean (The error I get back from setattr is 'Boolean value expected').

Has the way that a Boolean is represented changed in Python 3.0?  This worked fine in Python 2.6.  I cannot get it to work and have tried values of False,True,0 and 1, all to no avail.

It sounds like a bug in the win32com API for 3.0 to me.

Further details below.

Many thanks to anyone that can help,

Sunny Carter
==============================================================================================================

I am writing a Python script to call across to Adobe Photoshop, to automate some image manipulation.  (For historical reasons I'm writing using Python rather than javascript or VB)

My problem is that my script works fine using Python 2.6, but fails after upgrading to Python 3.0 or 3.1.1.  I've converted the script to Python 3.0 format, and it all works except the call across the Photoshop API.

The problem seems to be with the win32 API call using a Boolean value (False in my python script) which is not recognised as a Boolean by Photoshop.

Details:
Script based in part on http://techarttiki.blogspot.com/2008/08/photoshop-scripting-with-python.html
Script uses pywin32 from http://sourceforge.net/projects/pywin32/files/
    - I have installed pywin32-214.win32-py2.6.exe for Python 2.6 and pywin32-214.win32-py3.0.exe for use with Python 3.0

Subset of the script:

    import win32com.client
    psApp = win32com.client.Dispatch('Photoshop.Application')
    doc = psApp.Open(os.path.abspath(psd_image.psd_filename))
    #  Here I do the image manipulation which I haven't included here as it is irrelevant (and working fine -
    # calling Photoshop and making it do stuff)
    psd_save_options = win32com.client.Dispatch("Photoshop.PNGSaveOptions")
    psd_save_options.Interlaced = False
    print("Save as %s" % (os.path.join(output_directory, psd_image.final_filename)))
    doc.SaveAs(os.path.join(output_directory, psd_image.final_filename),
               psd_save_options,
               True,
               2)  # lower case extension

Exception hit:

Unexpected error detail: <class 'pywintypes.com_error'>
Traceback (most recent call last):
  File "C:\brander\brander.py", line 6464, in <module> main()
  File "C:\brander\brander.py", line 6407, in main recf)
  File "C:\brander\brander.py", line 4303, in createBranding brand_widgets)
  File "C:\brander\brander.py", line 1961, in reconstructImageDirectory    brand_widgets)
  File "C:\brander\brander.py", line 1961, in reconstructImageDirectory     brand_widgets)
  File "C:\brander\brander.py", line 1961, in reconstructImageDirectory     brand_widgets)
  File "C:\brander\brander.py", line 1999, in reconstructImageDirectory     new_color_palette)
  File "C:\brander\brander.py", line 2519, in reconstructPSDImageFile   psd_save_options.Interlaced = False
  File "C:\Program Files\Python31\lib\site-packages\win32com\client\dynamic.py", line 550, in __setattr__     self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Adobe Photoshop' , 'Boolean value expected', None, 0, -2147220276), None)

Investigation tracing from pywintypes.py
The dll being loaded is
C:\WINDOWS\system32\pywintypes30.dll

Things tried so far
I've already tried setting psd_save_options.Interlaced to True, "False", 0, 1 and None.  In this, None gets further on in the script but then fails on the SaveAs call.  If I delete the psd_save_options.Interlaced line, then the script fails in exactly the same way on the SaveAs call (this time the parameter True is the culprit).

As I say - the same script works fine using Python 2.6 and pywin32-214.win32-py2.6.exe.  I am running on Windows XP.

Help?
If anyone can help with a solution that would be great.  If there is no way of fixing, is it possible to run my python script using Python 2.6 but call out to a separate script running Python 3.0 for the part where I require 3.0?  (not included here)

Thanks so much,

Sunny Carter
<http://www.metaswitch.com/>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20100104/8425b1cd/attachment.htm>


More information about the python-win32 mailing list