From skippy.hammond at gmail.com Wed Jun 1 04:09:23 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 01 Jun 2011 12:09:23 +1000 Subject: [python-win32] Excel "stopped working" after reading in sheet names In-Reply-To: <4DE4A220.1080905@timgolden.me.uk> References: <8de3eae44155fbd7a60ae1c0cbd43cc8@mail.gmail.com> <4DE4A220.1080905@timgolden.me.uk> Message-ID: <4DE59F53.9090109@gmail.com> On 31/05/2011 6:09 PM, Tim Golden wrote: > On 30/05/2011 21:26, Mark Mordeca wrote: >> Greetings, >> >> I would appreciate any help I could get with the following problem. 30% >> of the time after running the following code to get the sheet names out >> of an excel file, I will receive a windows error saying that ?Microsoft >> Office Excel has stopped working?. > > A few points: > > * The underlying problem is almost certainly going to be a subtle > timing interaction around the refcounting on the pywin32 CDispatch > objects which are proxying for the underlying Windows objects. > It's a maze of twisty passages, so I'll let Mark or Roger comment > if they think there's something to be said. Unless I misunderstand, I don't think that will be the problem. The sample is simple enough that each of the Python objects will die deterministically (ie, without relying on GC etc), which means all COM references will also be managed deterministically. IOW, I think anyone running the sample will have exactly the same COM references being manipulated in same way each time it is run. I fear the problem will just be something to do with the local install of Excel. It might help if you can reproduce it on another box, or even try and reproduce it on the same box using something like wscript. I recently had a problem where firefox would regularly hang and need to be force stopped. After waiting for update to fix the problem, I bit-the-bullet and attached a debugger to a hanging instance to see if I could report a reasonable firefox bug on the issue. The stack frames led me to the conclusion opengl (or something like it) was being used. On a whim I looked for a new video driver and magically the problem went away. ie, a driver actually caused one single application on my box to look very much like that app - and that app alone - had a strange bug - but it turned out to be nothing to do with the application at all. Your problem might be similar. Also, FWIW, it isn't a "windows error" as such - it is simply an excel crash which Windows Error Reporting is taking action on. A fairly subtle difference, but the point is that the crash is "simple", constrained to Excel itself and not something serious that is upsetting Windows. Not that that helps you though... Mark From mc at mclaveau.com Wed Jun 1 10:59:36 2011 From: mc at mclaveau.com (Michel Claveau) Date: Wed, 1 Jun 2011 10:59:36 +0200 Subject: [python-win32] inserting an image in a word (2003) document In-Reply-To: <4DE55C2A.4000300@gmail.com> References: <4DE55C2A.4000300@gmail.com> Message-ID: <20CBDB6BF6334C75A57848ECF76A36EE@M14> Hi! Try: sel = self.app.Selection sel.InlineShapes.AddPicture("C:\\monimage.jpg",False,True) @-salutations -- Michel Claveau From mark.mordeca at prosensus.ca Wed Jun 1 17:07:38 2011 From: mark.mordeca at prosensus.ca (Mark Mordeca) Date: Wed, 1 Jun 2011 11:07:38 -0400 Subject: [python-win32] Excel "stopped working" after reading in sheet names In-Reply-To: <4DE59F53.9090109@gmail.com> References: <8de3eae44155fbd7a60ae1c0cbd43cc8@mail.gmail.com> <4DE4A220.1080905@timgolden.me.uk> <4DE59F53.9090109@gmail.com> Message-ID: <173fe53f4ed6afa61a40b551a5bdab7e@mail.gmail.com> Thanks for your reply. I tested this on another box and I did not get the error. I then tried different code that uses COM to manipulate Excel on my machine which I know works and has worked in the past and I ended up getting the error with that code. So I know for sure it is the local install of Excel on my machine. Thanks for your help Mark and Tim. I greatly appreciate it. Sorry to bother you and the mailing list with a problem that was not rooted in pywin32. Mark -----Original Message----- From: Mark Hammond [mailto:skippy.hammond at gmail.com] Sent: Tuesday, May 31, 2011 10:09 PM To: Mark Mordeca Cc: python-win32 at python.org Subject: Re: [python-win32] Excel "stopped working" after reading in sheet names On 31/05/2011 6:09 PM, Tim Golden wrote: > On 30/05/2011 21:26, Mark Mordeca wrote: >> Greetings, >> >> I would appreciate any help I could get with the following problem. 30% >> of the time after running the following code to get the sheet names out >> of an excel file, I will receive a windows error saying that "Microsoft >> Office Excel has stopped working". > > A few points: > > * The underlying problem is almost certainly going to be a subtle > timing interaction around the refcounting on the pywin32 CDispatch > objects which are proxying for the underlying Windows objects. > It's a maze of twisty passages, so I'll let Mark or Roger comment > if they think there's something to be said. Unless I misunderstand, I don't think that will be the problem. The sample is simple enough that each of the Python objects will die deterministically (ie, without relying on GC etc), which means all COM references will also be managed deterministically. IOW, I think anyone running the sample will have exactly the same COM references being manipulated in same way each time it is run. I fear the problem will just be something to do with the local install of Excel. It might help if you can reproduce it on another box, or even try and reproduce it on the same box using something like wscript. I recently had a problem where firefox would regularly hang and need to be force stopped. After waiting for update to fix the problem, I bit-the-bullet and attached a debugger to a hanging instance to see if I could report a reasonable firefox bug on the issue. The stack frames led me to the conclusion opengl (or something like it) was being used. On a whim I looked for a new video driver and magically the problem went away. ie, a driver actually caused one single application on my box to look very much like that app - and that app alone - had a strange bug - but it turned out to be nothing to do with the application at all. Your problem might be similar. Also, FWIW, it isn't a "windows error" as such - it is simply an excel crash which Windows Error Reporting is taking action on. A fairly subtle difference, but the point is that the crash is "simple", constrained to Excel itself and not something serious that is upsetting Windows. Not that that helps you though... Mark From jacobk at mailzone.co.za Wed Jun 1 18:24:20 2011 From: jacobk at mailzone.co.za (Jacob Kruger) Date: Wed, 1 Jun 2011 18:24:20 +0200 Subject: [python-win32] Trying to get py2exe to install/work on my windows7 64 bit machine Message-ID: When I try installing: py2exe-0.6.9.win64-py2.7.amd64.exe It tells me: Cannot install Python version 2.7 required, which was not found in the registry. Any thoughts/suggestions? When I ran: pywin32-216.win32-py2.7.exe it was quite happy to install to c:\python27 Have tried restarting machine, etc., and can't remember if ran some other scripts on my windows7 32 bit machine before it worked, but anyway. Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' -------------- next part -------------- An HTML attachment was scrubbed... URL: From planders at gmail.com Wed Jun 1 19:04:24 2011 From: planders at gmail.com (Preston Landers) Date: Wed, 1 Jun 2011 12:04:24 -0500 Subject: [python-win32] Trying to get py2exe to install/work on my windows7 64 bit machine In-Reply-To: References: Message-ID: Looks like you downloaded the 64 bit version of py2exe but are trying to use it with the 32 bit version of Python. Either get the 64 bit version of Python 2.7, or else the 32 bit version of py2exe. good luck, Preston On Wed, Jun 1, 2011 at 11:24 AM, Jacob Kruger wrote: > When I try installing: > py2exe-0.6.9.win64-py2.7.amd64.exe > > It tells me: > Cannot install > Python version 2.7 required, which was not found in the registry. > > Any thoughts/suggestions? > > When I ran: > pywin32-216.win32-py2.7.exe > > it was quite happy to install to c:\python27 > > Have tried restarting machine, etc., and can't remember if ran some other > scripts on my windows7 32 bit machine before it worked, but anyway. > > Stay well > > Jacob Kruger > Blind Biker > Skype: BlindZA > '...fate had broken his body, but not his spirit...' > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stef.mientki at gmail.com Wed Jun 1 19:10:59 2011 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 01 Jun 2011 19:10:59 +0200 Subject: [python-win32] inserting an image in a word (2003) document In-Reply-To: <20CBDB6BF6334C75A57848ECF76A36EE@M14> References: <4DE55C2A.4000300@gmail.com> <20CBDB6BF6334C75A57848ECF76A36EE@M14> Message-ID: <4DE672A3.6080100@gmail.com> On 01-06-2011 10:59, Michel Claveau wrote: > Hi! > > Try: > sel = self.app.Selection > sel.InlineShapes.AddPicture("C:\\monimage.jpg",False,True) > > @-salutations thanks Michel, works like a charm. Maybe the code I posted was also (almost) good, but I had another error too in my code. But after trying 10 .. 20 different combinations, you loose control. With your 2 lines of code it was easy to find that other code. cheers, Stef From jacobk at mailzone.co.za Fri Jun 3 08:30:02 2011 From: jacobk at mailzone.co.za (Jacob Kruger) Date: Fri, 3 Jun 2011 08:30:02 +0200 Subject: [python-win32] 'exit is not defined' Message-ID: What I'm doing is trying to open a text file, but if it's not there, then I tell the code to exit(), and while it works when running the source code using the python executable, after I have run the code through py2exe, and then try testing it, I get the following message: Traceback (most recent call last): File "mapData.py", line 39, in NameError: name 'exit' is not defined The following is the actual little bit of code that's generating this after being py2exe'ed - the last line is the line number being mentioned above: try: fData = open(sMapName + ".txt", "r") except: fData = None finally: if not bool(fData): print("invalid map name - " + sMapName + ".txt"); exit() Any thoughts/ideas/alternative workarounds? Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' From jacobk at mailzone.co.za Fri Jun 3 10:33:48 2011 From: jacobk at mailzone.co.za (Jacob Kruger) Date: Fri, 3 Jun 2011 10:33:48 +0200 Subject: [python-win32] 'exit is not defined' In-Reply-To: Message-ID: Sorry, but replying on list now as well. Either way, seems that while did have the import statement higher up in that file for the sys module, maybe there was something interfering with that, since when changed that statement to sys.exit() it's now working without any issues. And, secondly, the reason I'm using tabs to handle indentation is partly since the editor I specifically am using for python source editing prefers that for use by VI/blind guys, and that's why it suits me, but anyway... Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' ----- Original Message --------------- Subject: Re: [python-win32] 'exit is not defined' From: "Amaury Forgeot d'Arc" Date: Fri, 3 Jun 2011 09:43:47 +0200 To: Jacob Kruger >Hi, > >2011/6/3 Jacob Kruger : >> What I'm doing is trying to open a text file, but if it's not there, then I tell the code to exit(), and while it works when running the source code using the python executable, after I have run the code through py2exe, and then try testing it, I get the following message: >> >> Traceback (most recent call last): >> File "mapData.py", line 39, in >> NameError: name 'exit' is not defined >> >> The following is the actual little bit of code that's generating this after being py2exe'ed - the last line is the line number being mentioned above: >> >> try: >> ? ? ? ?fData = open(sMapName + ".txt", "r") >> except: >> ? ? ? ?fData = None >> finally: >> ? ? ? ?if not bool(fData): print("invalid map name - " + sMapName + ".txt"); exit() >> >> >> Any thoughts/ideas/alternative workarounds? > >"exit" is in the sys module, you shoud have an "import sys" somewhere, >and then calll "sys.exit()". >Maybe you tested your script from some IDE which already does "from >sys import exit" for you? > >By the way, your code could be improved in several ways: >- don't use tabs for indentation, use spaces instead. >- "if not bool(fData)" could be rewritten as "if not fData" >- open() always return a file object, so the logic could be: > >import sys > >try: > fData = open(sMapName + ".txt", "r") >except IOError: > print("invalid map name - " + sMapName + ".txt") > sys.exit() > >I hope I did not spoil all the fun - coding with Python is fun! > >-- >Amaury Forgeot d'Arc From usharma01 at gmail.com Fri Jun 3 12:55:15 2011 From: usharma01 at gmail.com (Umesh Sharma) Date: Fri, 3 Jun 2011 16:25:15 +0530 Subject: [python-win32] pywin32 py2exe Message-ID: hi, i am working on outlook automation , in my code i am using dispatchwithevents method for capturing events of outlook as newmail ,itemsend .The code works fine in command line but after converting it into exe file using py2exe ,the generated exe file crashes . I am not using dispatch for generating object of outlook because i have to do event handling. here is my code ///// import time, win32event, win32com.client, pythoncom class xlEv: def OnNewMailEx(self,entry): print 'event happened' xl=win32com.client.DispatchWithEvents("Outlook.Application", xlEv) i = input #waiting till event captured ///// Thanks Umesh Kumar Sharma -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Fri Jun 3 16:53:56 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 03 Jun 2011 15:53:56 +0100 Subject: [python-win32] Excel "stopped working" after reading in sheet names In-Reply-To: <173fe53f4ed6afa61a40b551a5bdab7e@mail.gmail.com> References: <8de3eae44155fbd7a60ae1c0cbd43cc8@mail.gmail.com> <4DE4A220.1080905@timgolden.me.uk> <4DE59F53.9090109@gmail.com> <173fe53f4ed6afa61a40b551a5bdab7e@mail.gmail.com> Message-ID: <4DE8F584.2070805@timgolden.me.uk> On 01/06/2011 16:07, Mark Mordeca wrote: > Thanks for your reply. I tested this on another box and I did not get the > error. I then tried different code that uses COM to manipulate Excel on > my machine which I know works and has worked in the past and I ended up > getting the error with that code. So I know for sure it is the local > install of Excel on my machine. > > Thanks for your help Mark and Tim. I greatly appreciate it. Sorry to > bother you and the mailing list with a problem that was not rooted in > pywin32. Speaking for myself, I'm glad you brought it up. Sometimes these things throw up real (if obscure) bugs; sometimes they give other readers ideas they might not have thought of. Feel free to ask again :) TJG From sharpblade1 at gmail.com Fri Jun 3 21:14:51 2011 From: sharpblade1 at gmail.com (sharpblade) Date: Fri, 3 Jun 2011 20:14:51 +0100 Subject: [python-win32] 'exit is not defined' In-Reply-To: References: Message-ID: Why do you need a finally block there at all? Just terminate on the exception, there is no point in setting it to None then checking if its none. ~Tom On Fri, Jun 3, 2011 at 9:33 AM, Jacob Kruger wrote: > Sorry, but replying on list now as well. > > Either way, seems that while did have the import statement higher up in that file for the sys module, maybe there was something interfering with that, since when changed that statement to sys.exit() it's now working without any issues. > > And, secondly, the reason I'm using tabs to handle indentation is partly since the editor I specifically am using for python source editing prefers that for use by VI/blind guys, and that's why it suits me, but anyway... > > Jacob Kruger > Blind Biker > Skype: BlindZA > '...fate had broken his body, but not his spirit...' > > > ----- Original Message --------------- > > Subject: Re: [python-win32] 'exit is not defined' > ? From: "Amaury Forgeot d'Arc" > ? Date: Fri, 3 Jun 2011 09:43:47 +0200 > ? ? To: Jacob Kruger > >>Hi, >> >>2011/6/3 Jacob Kruger : >>> What I'm doing is trying to open a text file, but if it's not there, then I tell the code to exit(), and while it works when running the source code using the python executable, after I have run the code through py2exe, and then try testing it, I get the following message: >>> >>> Traceback (most recent call last): >>> File "mapData.py", line 39, in >>> NameError: name 'exit' is not defined >>> >>> The following is the actual little bit of code that's generating this after being py2exe'ed - the last line is the line number being mentioned above: >>> >>> try: >>> ? ? ? ?fData = open(sMapName + ".txt", "r") >>> except: >>> ? ? ? ?fData = None >>> finally: >>> ? ? ? ?if not bool(fData): print("invalid map name - " + sMapName + ".txt"); exit() >>> >>> >>> Any thoughts/ideas/alternative workarounds? >> >>"exit" is in the sys module, you shoud have an "import sys" somewhere, >>and then calll "sys.exit()". >>Maybe you tested your script from some IDE which already does "from >>sys import exit" for you? >> >>By the way, your code could be improved in several ways: >>- don't use tabs for indentation, use spaces instead. >>- "if not bool(fData)" could be rewritten as "if not fData" >>- open() always return a file object, so the logic could be: >> >>import sys >> >>try: >> ? ?fData = open(sMapName + ".txt", "r") >>except IOError: >> ? ?print("invalid map name - " + sMapName + ".txt") >> ? ?sys.exit() >> >>I hope I did not spoil all the fun - coding with Python is fun! >> >>-- >>Amaury Forgeot d'Arc > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From Andrew.MacIntyre at acma.gov.au Mon Jun 6 02:40:31 2011 From: Andrew.MacIntyre at acma.gov.au (Andrew MacIntyre) Date: Mon, 6 Jun 2011 00:40:31 +0000 Subject: [python-win32] 'exit is not defined' [SEC=UNCLASSIFIED] In-Reply-To: References: Message-ID: > Jacob Kruger wrote: > > Either way, seems that while did have the import statement higher up in that > file for the sys module, maybe there was something interfering with that, > since when changed that statement to sys.exit() it's now working without > any issues. I think you haven't yet caught up fully with how namespaces and scopes work in Python - the "Modules" section of the Python Tutorial might be a good place to start. -------------------------> "These thoughts are mine alone!" <--------- Andrew MacIntyre?????????? Operations Branch tel:?? +61 2 6219 5356???? Communications Infrastructure Division fax:?? +61 2 6253 3277???? Australian Communications & Media Authority email: andrew.macintyre at acma.gov.au??????????? http://www.acma.gov.au/ NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. From usharma01 at gmail.com Mon Jun 6 12:13:23 2011 From: usharma01 at gmail.com (usharma01 at gmail.com) Date: Mon, 6 Jun 2011 15:43:23 +0530 Subject: [python-win32] python-win32 Digest, Vol 99, Issue 5 Message-ID: <002b01cc2432$64472290$2cd567b0$@org> Send python-win32 mailing list submissions to python-win32 at python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/python-win32 or, via email, send a message with subject or body 'help' to python-win32-request at python.org You can reach the person managing the list at python-win32-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of python-win32 digest..." Today's Topics: 1. Re: 'exit is not defined' [SEC=UNCLASSIFIED] (Andrew MacIntyre) ---------------------------------------------------------------------- Message: 1 Date: Mon, 6 Jun 2011 00:40:31 +0000 From: "Andrew MacIntyre" To: "python-win32 at python.org" Subject: Re: [python-win32] 'exit is not defined' [SEC=UNCLASSIFIED] Message-ID: Content-Type: text/plain; charset=iso-8859-1 > Jacob Kruger wrote: > > Either way, seems that while did have the import statement higher up in that > file for the sys module, maybe there was something interfering with that, > since when changed that statement to sys.exit() it's now working without > any issues. I think you haven't yet caught up fully with how namespaces and scopes work in Python - the "Modules" section of the Python Tutorial might be a good place to start. -------------------------> "These thoughts are mine alone!" <--------- Andrew MacIntyre?????????? Operations Branch tel:?? +61 2 6219 5356???? Communications Infrastructure Division fax:?? +61 2 6253 3277???? Australian Communications & Media Authority email: andrew.macintyre at acma.gov.au??????????? http://www.acma.gov.au/ NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. ------------------------------ _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 End of python-win32 Digest, Vol 99, Issue 5 ******************************************* From usharma01 at gmail.com Mon Jun 6 12:13:35 2011 From: usharma01 at gmail.com (usharma01 at gmail.com) Date: Mon, 6 Jun 2011 15:43:35 +0530 Subject: [python-win32] python-win32 Digest, Vol 99, Issue 5 Message-ID: <002c01cc2432$6733bb30$359b3190$@org> Send python-win32 mailing list submissions to python-win32 at python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/python-win32 or, via email, send a message with subject or body 'help' to python-win32-request at python.org You can reach the person managing the list at python-win32-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of python-win32 digest..." Today's Topics: 1. Re: 'exit is not defined' [SEC=UNCLASSIFIED] (Andrew MacIntyre) ---------------------------------------------------------------------- Message: 1 Date: Mon, 6 Jun 2011 00:40:31 +0000 From: "Andrew MacIntyre" To: "python-win32 at python.org" Subject: Re: [python-win32] 'exit is not defined' [SEC=UNCLASSIFIED] Message-ID: Content-Type: text/plain; charset=iso-8859-1 > Jacob Kruger wrote: > > Either way, seems that while did have the import statement higher up in that > file for the sys module, maybe there was something interfering with that, > since when changed that statement to sys.exit() it's now working without > any issues. I think you haven't yet caught up fully with how namespaces and scopes work in Python - the "Modules" section of the Python Tutorial might be a good place to start. -------------------------> "These thoughts are mine alone!" <--------- Andrew MacIntyre?????????? Operations Branch tel:?? +61 2 6219 5356???? Communications Infrastructure Division fax:?? +61 2 6253 3277???? Australian Communications & Media Authority email: andrew.macintyre at acma.gov.au??????????? http://www.acma.gov.au/ NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. ------------------------------ _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 End of python-win32 Digest, Vol 99, Issue 5 ******************************************* From skippy.hammond at gmail.com Mon Jun 6 15:16:54 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 06 Jun 2011 23:16:54 +1000 Subject: [python-win32] 'exit is not defined' In-Reply-To: References: Message-ID: <4DECD346.90905@gmail.com> On 3/06/2011 4:30 PM, Jacob Kruger wrote: > What I'm doing is trying to open a text file, but if it's not there, then I tell the code to exit(), and while it works when running the source code using the python executable, after I have run the code through py2exe, and then try testing it, I get the following message: > > Traceback (most recent call last): > File "mapData.py", line 39, in > NameError: name 'exit' is not defined > > The following is the actual little bit of code that's generating this after being py2exe'ed - the last line is the line number being mentioned above: > > try: > fData = open(sMapName + ".txt", "r") > except: > fData = None > finally: > if not bool(fData): print("invalid map name - " + sMapName + ".txt"); exit() > > > Any thoughts/ideas/alternative workarounds? IIRC, exit() is added by site.py - I'd start looking what is going wrong in that module in your environment... Mark From skippy.hammond at gmail.com Mon Jun 6 15:19:07 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 06 Jun 2011 23:19:07 +1000 Subject: [python-win32] pywin32 py2exe In-Reply-To: References: Message-ID: <4DECD3CB.1060806@gmail.com> On 3/06/2011 8:55 PM, Umesh Sharma wrote: > hi, > i am working on outlook automation , in my code i am using > dispatchwithevents method for capturing events of outlook as newmail > ,itemsend .The code works fine in command line but after converting it > into exe file using py2exe ,the generated exe file crashes . What do you mean by "crashes"? > I am not using dispatch for generating object of outlook because i have > to do event handling. > here is my code > ///// > import time, win32event, win32com.client, pythoncom > class xlEv: > def OnNewMailEx(self,entry): > print 'event happened' > xl=win32com.client.DispatchWithEvents("Outlook.Application", xlEv) > i = input #waiting till event captured Didn't we already exchange email about this? You probably can't use input here - you want pythoncom.PumpMessages... Mark From usharma01 at gmail.com Mon Jun 6 15:23:55 2011 From: usharma01 at gmail.com (Umesh Sharma) Date: Mon, 6 Jun 2011 18:53:55 +0530 Subject: [python-win32] pywin32 py2exe In-Reply-To: <4DECD3CB.1060806@gmail.com> References: <4DECD3CB.1060806@gmail.com> Message-ID: crashes means it just after double clicking on exe file it opens prompt window and after some mili second it closes. And about that part i have used pump message but first i want that exe of this file should run properly. -------------- next part -------------- An HTML attachment was scrubbed... URL: From malaclypse2 at gmail.com Mon Jun 6 20:19:33 2011 From: malaclypse2 at gmail.com (Jerry Hill) Date: Mon, 6 Jun 2011 14:19:33 -0400 Subject: [python-win32] pywin32 py2exe In-Reply-To: References: Message-ID: On Fri, Jun 3, 2011 at 6:55 AM, Umesh Sharma wrote: > i = input ? ?#waiting till event captured This doesn't wait for anything. It assigns the function input to the local name i. You probably want "i = input()" instead, which will force the dos window to stay open until the user hits enter. Plus, as Mark already pointed out, you'll probably never get any notification of your event if you're not running the message pump. I'm not sure how this could "work fine" on the command line. -- Jerry From gmail at nekolyanich.com Tue Jun 7 13:11:57 2011 From: gmail at nekolyanich.com (nekolyanich) Date: Tue, 7 Jun 2011 11:11:57 +0000 (UTC) Subject: [python-win32] can't import dde module after importing win32ui References: <1300898289.2808.8.camel@florete.mza.com> Message-ID: Michel Claveau mclaveau.com> writes: > > Hi! > > I have also/another problem with win32ui in 216 version: on several COM's > servers, if the line > import win32ui > is present, servers can not be contacted. > If I comment the line, no more problem. Uncomment, problem is coming back. > > Waiting a solution, I come back to 214. > > @-salutations Saw this bug, and 214 version helped me with my 32-bit xp. But in production i'd have 64-bit mashine, and downgrading to 214 version don't helps. Any ideas, how to make it work? From emmanuel.cazenave at gmail.com Tue Jun 7 14:49:38 2011 From: emmanuel.cazenave at gmail.com (emmanuel CAZENAVE) Date: Tue, 7 Jun 2011 14:49:38 +0200 Subject: [python-win32] How to create a windows service and set the service name through command line option Message-ID: Hi, I want to have a script which creates a windows service, and that the name of the service could be fed by user input. Example: *createservice --servicename=whatevernameichoose* * * I came out with a solution which is below: class WindowsService(win32serviceutil.ServiceFramework): _svc_name_ = "dummyname" _svc_display_name_ = "dummydisplayname" def __init__(self, args): self.__class__._svc_name_ = args[0] win32serviceutil.ServiceFramework.__init__(self, args) # My question is not about starting and stopping service def SvcStop(self): stop_service() def SvcDoRun(self): start_service() def main(): import argparse parser = argparse.ArgumentParser() parser.add_argument('action', type=str, nargs='?') parser.add_argument('-s', type=str, nargs='?', action='store', dest='servicename', help="Name of the service to handle") cmdargs = parser.parse_args() if cmdargs.servicename: WindowsService._svc_name_ = cmdargs.servicename win32serviceutil.HandleCommandLine(WindowsService, customInstallOptions='s') if __name__=='__main__': main() As you might notice, my solution is pretty dirty. But it works, I can install and remove services with a custom name not hard coded in the script. My question is 'does someone knows a cleaner solution to achieve this ?' Cleaner would be: not override _svc_name_ dynamically, and not call another commandline parser before the one called by win32serviceutil.... As far as I understand, you can handle your customInstallOptions with a customInstallOptionsHandler, but that one is called after the creation of the service, so by that time the name of the service is already set. That's why I came out with that solution....... Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From jpiee at aim.com Thu Jun 9 00:45:48 2011 From: jpiee at aim.com (jpiee at aim.com) Date: Wed, 8 Jun 2011 18:45:48 -0400 (EDT) Subject: [python-win32] How to hide the cursor in Windows when dragging and dropping Message-ID: <8CDF444F1DC3C1E-B80-1058E@webmail-m155.sysops.aol.com> After hours of searching google, with little luck, I'm wondering if anybody knows how to either hide the cursor, or set a custom cursor (which could be made blank) in Windows when dragging and dropping. I'm writing a program which draws its own mouse using openGL, and normally the mouse hides just fine, but when I drag files onto the program's window, the windows cursor shows the drag-and-drop square and will not hide. ShowCursor(False) and SetCursor(None) (in python) are inconsistent for hiding the cursor. Ideally, if anybody knew how to do this in Python using pywin32, that would be ideal, as that's the language my project is using, but if I have to code this up in another language I will. Alternately, if anybody knows when ShowCursor and SetCursor will guarantee to hide the cursor, whether this has to do with window focus or something related, that would also be helpful. I've tried the following: while ShowCursor(False) > -1: pass This code works sometimes, and I can't figure out reliable when it does. It doesn't seem to have to do with window focus. It works sometimes when I drag a file from a folder, and never when I drag a file from the desktop. It also never hides the cursor the first time I drag a file. I've found this page: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dodragdrop.aspx#Y1354 I cannot get the C++ code to compile, and I get exceptions when I use the C# and VB versions. I've copied cursors from C:\Windows\Cursors to the directory with the executable as 3dwarro.cur and 3dwno.cur. When I comment out the try clauses, when it tries to load the cursors it says they are corrupt. I've also found this page: http://www.rockhoppertech.com/java-drag-and-drop-faq.html. It says to set the DragContext's cursor to null and then to your cursor in dragOver. The page is in Java, and I don't know how to do what it is saying. Many thanks in advance! -------------- next part -------------- An HTML attachment was scrubbed... URL: From steffen.froemer at gns-systems.de Thu Jun 9 22:58:47 2011 From: steffen.froemer at gns-systems.de (=?ISO-8859-1?Q?Steffen_Fr=F6mer?=) Date: Thu, 09 Jun 2011 22:58:47 +0200 Subject: [python-win32] py2exe & win32wnet - ImportError Message-ID: <4DF13407.80800@gns-systems.de> Hello, i am having some trouble to include win32wnet library into my code. Using this inside python, all works fine. When i make executable using py2exe, i get ImportError on importing the module win32wnet. Have someone an idea? Regards, Steffen System: Windows7 Professional x86_64 Python 2.7.1 (32bit) ## Exception Error ## --------------------------------- MemoryLoadLibrary failed loading win32wnet.pyd ## [diredit::getUNCPath(68)] Traceback (most recent call last): File "tfm\util\fileio\diredit.pyo", line 65, in getUNCPath File "zipextimporter.pyo", line 98, in load_module ImportError: MemoryLoadLibrary failed loading win32wnet.pyd ## snip of code from setup.py ## ------------------------------------------------- includes = ["sip", "PyQt4.QtCore", "pubsub.*", "pubsub.core.*", "pubsub.core.kwargs.*", "lxml", "gzip", "lxml._elementpath", "win32api", "win32wnet", ] # workaround of following error # ... ImportError: MemoryLoadLibrary failed loading win32api.pyd dll_excludes = [ "mswsock.dll", "powrprof.dll" ] From steffen.froemer at gns-systems.de Fri Jun 10 09:32:22 2011 From: steffen.froemer at gns-systems.de (=?ISO-8859-1?Q?Steffen_Fr=F6mer?=) Date: Fri, 10 Jun 2011 09:32:22 +0200 Subject: [python-win32] py2exe & win32wnet - ImportError In-Reply-To: <4DF13407.80800@gns-systems.de> References: <4DF13407.80800@gns-systems.de> Message-ID: <4DF1C886.5000609@gns-systems.de> Hello, i found out. that all works fine, if i change py2exe-option 'bundle_files' from 1 to 3. Someone know, where the problem is? Regards, Steffen setup( package_dir = {"" : "src"}, packages = packages, options={ "py2exe" : { "includes" : includes, 'dll_excludes': dll_excludes, #"bundle_files": 1, # bundle everything, including the Python interpreter "bundle_files": 3, # bundle nothing, workaround for using win32wnet.pyd "compressed": 1, "optimize" : 2}}, zipfile = None, On 06/09/2011 10:58 PM, Steffen Fr?mer wrote: > Hello, > > i am having some trouble to include win32wnet library into my code. > Using this inside python, all works fine. When i make executable using > py2exe, i get ImportError on importing the module win32wnet. > > Have someone an idea? > > Regards, > Steffen > > System: > Windows7 Professional x86_64 > Python 2.7.1 (32bit) > > > ## Exception Error ## > --------------------------------- > MemoryLoadLibrary failed loading win32wnet.pyd ## > [diredit::getUNCPath(68)] > Traceback (most recent call last): > File "tfm\util\fileio\diredit.pyo", line 65, in getUNCPath > File "zipextimporter.pyo", line 98, in load_module > ImportError: MemoryLoadLibrary failed loading win32wnet.pyd > > > ## snip of code from setup.py ## > ------------------------------------------------- > includes = ["sip", > "PyQt4.QtCore", > "pubsub.*", > "pubsub.core.*", > "pubsub.core.kwargs.*", > "lxml", > "gzip", > "lxml._elementpath", > "win32api", > "win32wnet", > ] > > # workaround of following error > # ... ImportError: MemoryLoadLibrary failed loading win32api.pyd > dll_excludes = [ "mswsock.dll", "powrprof.dll" ] > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From skippy.hammond at gmail.com Fri Jun 10 16:11:30 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Sat, 11 Jun 2011 00:11:30 +1000 Subject: [python-win32] can't import dde module after importing win32ui In-Reply-To: References: <1300898289.2808.8.camel@florete.mza.com> Message-ID: <4DF22612.406@gmail.com> On 7/06/2011 9:11 PM, nekolyanich wrote: > Michel Claveau mclaveau.com> writes: > >> >> Hi! >> >> I have also/another problem with win32ui in 216 version: on several COM's >> servers, if the line >> import win32ui >> is present, servers can not be contacted. >> If I comment the line, no more problem. Uncomment, problem is coming back. >> >> Waiting a solution, I come back to 214. >> >> @-salutations > > Saw this bug, and 214 version helped me with my 32-bit xp. But in production i'd > have 64-bit mashine, and downgrading to 214 version don't helps. Any ideas, how > to make it work? It will be something to do with the manifest and the mfc libraries. I think that even though the mfc dlls are installed with pywin32, it might not work as hoped :) Can you find a redistributable version of the MFC dlls you can try? I can't explain why the 32 vs 64bit versions behave differently other than what libraries are already installed. Sorry, not much help... Mark From rays at blue-cove.com Fri Jun 10 19:19:08 2011 From: rays at blue-cove.com (RayS) Date: Fri, 10 Jun 2011 10:19:08 -0700 Subject: [python-win32] py2.7 and multiple DDE servers on Win32, possible? Message-ID: <20110610171910.GPJC16474.fed1rmfepo201.cox.net@fed1rmimpo01.cox.net> Hello I know that the default behavior since 2.? has been only one DDE server allowed. Is it possible to back-hack this restriction? I asked similarly a while back http://mail.python.org/pipermail/python-win32/2010-October/010774.html and Roger replied: "It was done through some low-level hacks to create new C functions on the fly, which set off DEP and crashed in a 64-bit build. " http://python.net/crew/pirx/win32/dde.zip (http://www.koders.com/cpp/fid7F744C525820DA799D8AB0484F2F97152DF30852.aspx?s=setwindowshookex) is apparently an older implementation and attempting to import the included dde.pyd fails with " : DLL load failed: The specified module could not be found." whether placed in Python27\DLLs or Python27\Lib\site-packages\pythonwin. I assume that it would need to be compiled with MVC2008/Py2.7 to hope to work... I have a legacy 6 year old DDE client app that I would really like to support with a new data server... Ray From greg.ewing at canterbury.ac.nz Sat Jun 11 08:55:44 2011 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 11 Jun 2011 18:55:44 +1200 Subject: [python-win32] Creating PyCComboBox? Message-ID: <4DF31170.6040600@canterbury.ac.nz> How are you supposed to create a PyCComboBox? There doesn't seem to be a CreateComboBox function anywhere. I tried using CreateControl("COMBOBOX", ...) but it says that the CLSID is invalid. -- Greg From rupole at hotmail.com Sat Jun 11 12:47:22 2011 From: rupole at hotmail.com (Roger Upole) Date: Sat, 11 Jun 2011 06:47:22 -0400 Subject: [python-win32] py2.7 and multiple DDE servers on Win32, possible? Message-ID: If you can build the dde module yourself, reenabling multiple servers for 32-bit is just a matter of uncommenting // #define _CALLHACK_ in stddde.cpp. Roger -------------- next part -------------- An HTML attachment was scrubbed... URL: From vernondcole at gmail.com Sat Jun 11 18:09:06 2011 From: vernondcole at gmail.com (Vernon Cole) Date: Sat, 11 Jun 2011 10:09:06 -0600 Subject: [python-win32] Creating PyCComboBox? In-Reply-To: <4DF31170.6040600@canterbury.ac.nz> References: <4DF31170.6040600@canterbury.ac.nz> Message-ID: I've been intending to make enough time to create a combobox for PyGUI. In my humble opinion, the combobox provided by Windows GUI is brain damaged to the point of utter frustration and should not be used for human consumption. I sent an epistle to this effect to the wxpython group, and got the answer "that's what the OS provides." The problem is that the Windows combobox does not allow for the user to type more than one letter to select an item from the list -- there is no provision for matching to a substring. Let's say that I am trying to select "Wisconsin" from a list of states of the U.S. I type the "W" and get "Washington". Then I type the "I" and get "Idaho". Most frustrating. If I am trying to select "1950" from a list of acceptable years, I must use the mouse, or scroll down 50 times from "1900". Yech! I think that a proper combobox will have to be coded at a higher level. I hope I'm wrong. -- Vernon Cole On Sat, Jun 11, 2011 at 12:55 AM, Greg Ewing wrote: > How are you supposed to create a PyCComboBox? There > doesn't seem to be a CreateComboBox function anywhere. > > I tried using CreateControl("COMBOBOX", ...) but it > says that the CLSID is invalid. > > -- > Greg > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rays at blue-cove.com Sat Jun 11 17:05:16 2011 From: rays at blue-cove.com (RayS) Date: Sat, 11 Jun 2011 08:05:16 -0700 Subject: [python-win32] py2.7 and multiple DDE servers on Win32, possible? In-Reply-To: References: Message-ID: <20110611150631.IGVO22406.fed1rmfepo203.cox.net@fed1rmimpo02.cox.net> Nice, I'll give it a shot, providing they compile with free VS2008 Express (?) The old page is a tad out of date http://starship.python.net/crew/mhammond/win32/BuildingExtensions.html but it seems this might help http://mattptr.net/2010/07/28/building-python-extensions-in-a-modern-windows-environment/ I'll also check with Enthought (I have their full MKL edition). Ray At 03:47 AM 6/11/2011, Roger Upole wrote: >If you can build the dde module yourself, reenabling multiple servers >for 32-bit is just a matter of uncommenting > >// #define _CALLHACK_ > >in stddde.cpp. > > Roger -------------- next part -------------- An HTML attachment was scrubbed... URL: From jsheehan at jennasys.com Sat Jun 11 22:28:41 2011 From: jsheehan at jennasys.com (John Sheehan) Date: Sat, 11 Jun 2011 13:28:41 -0700 Subject: [python-win32] Creating PyCComboBox? In-Reply-To: References: <4DF31170.6040600@canterbury.ac.nz> Message-ID: Just my opinion, but if anyone decides to create a combo box, the one that has been part of MS Access since at least version 2.0 would be the one to model it after. I have yet to see any combo box in any language/platform/application that has worked as well as that one does. John Sheehan On Sat, 11 Jun 2011 09:09:06 -0700, Vernon Cole wrote: > I've been intending to make enough time to create a combobox for PyGUI. > In > my humble opinion, the combobox provided by Windows GUI is brain damaged > to > the point of utter frustration and should not be used for human > consumption. I sent an epistle to this effect to the wxpython group, and > got the answer "that's what the OS provides." > The problem is that the Windows combobox does not allow for the user to > type more than one letter to select an item from the list -- there is no > provision for matching to a substring. Let's say that I am trying to > select > "Wisconsin" from a list of states of the U.S. I type the "W" and get > "Washington". Then I type the "I" and get "Idaho". Most frustrating. > If I > am trying to select "1950" from a list of acceptable years, I must use > the > mouse, or scroll down 50 times from "1900". Yech! > I think that a proper combobox will have to be coded at a higher > level. I > hope I'm wrong. > -- > Vernon Cole From greg.ewing at canterbury.ac.nz Sun Jun 12 01:57:06 2011 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sun, 12 Jun 2011 11:57:06 +1200 Subject: [python-win32] Creating PyCComboBox? In-Reply-To: References: <4DF31170.6040600@canterbury.ac.nz> Message-ID: <4DF400D2.9010902@canterbury.ac.nz> Vernon Cole wrote: > The problem is that the Windows combobox does not allow for the user > to type more than one letter to select an item from the list I'm not sure it's necessary to replace the entire thing just to fix that -- it ought to be possible to override the keyboard event handling and do that part differently. Writing a complete replacement might be a good idea in the long run, but for the moment I just want to get something working for a particular project. Surely *someone* out there has used the PyComboBox object in pywin32? Google is being particularly unhelpful on this. -- Greg From famacoin at hotmail.com Mon Jun 13 14:00:26 2011 From: famacoin at hotmail.com (Famacoin) Date: Mon, 13 Jun 2011 07:30:26 -0430 Subject: [python-win32] Telit PhytonWin Message-ID: Hi We have a problem loading script for the GM862-GPS module over 7k when we try to load gives ERROR IN THE DOWNLOAD, and sometimes says OK but does not load the entire file, we have checked the serial port but do not get the fault?. Do not know if there is a newer version that we have is Telit PythonWin 1.5.2+ (#0, Oct 1 2004, 15:39:52) Please thank your help Best Regards Giovanny Perez FAMACOIN CA VENEZUELA -------------- next part -------------- An HTML attachment was scrubbed... URL: From tomforbes8 at hotmail.com Tue Jun 14 01:20:26 2011 From: tomforbes8 at hotmail.com (Tom) Date: Tue, 14 Jun 2011 00:20:26 +0100 Subject: [python-win32] Converting HTML formatting to Microsoft Word Message-ID: Hello, I have a Javascript rich text editor (Specifically the Yahoo UI libraries Simple Editor) which I have embedded within my web application. This produces formatted HTML from the users input which has to be placed within a Word document. The number of formatting options is limited - Bold, italics, underline, font size, font type, image insertion and lists. I thought this would be rather simple to automate using words COM interface, but I am having a lot of issues formatting the text using the COM interface - my solution so far parses the HTML using BeautifulSoup and rolls through each tag. If its a bold tag then it creates a range object at the end of the current one, inserts the bold text and sets the Bold attribute to True. My issue is that this doesn't work and produces confusing results - the text isn't formatted correctly and the Bold attribute is set to -1 (Which means a mix of both bold and non bold as far as I can tell). Does anyone have any experience doing anything similar to this, or can anyone give me a simpler way to do this? ~Tom From rupole at hotmail.com Tue Jun 14 07:13:58 2011 From: rupole at hotmail.com (Roger Upole) Date: Tue, 14 Jun 2011 01:13:58 -0400 Subject: [python-win32] py2.7 and multiple DDE servers on Win32, possible? Message-ID: Compiling with VC 2008 Express is going to be a problem. The free compiler doesn't seem to support using the atl/mfc headers and libraries. Roger -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Tue Jun 14 09:53:51 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 14 Jun 2011 08:53:51 +0100 Subject: [python-win32] Converting HTML formatting to Microsoft Word In-Reply-To: References: Message-ID: <4DF7138F.9090107@timgolden.me.uk> On 14/06/2011 00:20, Tom wrote: > Hello, > I have a Javascript rich text editor (Specifically the Yahoo UI > libraries Simple Editor) which I have embedded within my web > application. This produces formatted HTML from the users input which > has to be placed within a Word document. > The number of formatting options is limited - Bold, italics, > underline, font size, font type, image insertion and lists. I thought > this would be rather simple to automate using words COM interface, but > I am having a lot of issues formatting the text using the COM > interface - my solution so far parses the HTML using BeautifulSoup and > rolls through each tag. If its a bold tag then it creates a range > object at the end of the current one, inserts the bold text and sets > the Bold attribute to True. > > My issue is that this doesn't work and produces confusing results - > the text isn't formatted correctly and the Bold attribute is set to -1 > (Which means a mix of both bold and non bold as far as I can tell). > > Does anyone have any experience doing anything similar to this, or can > anyone give me a simpler way to do this? It's not 100% clear whether what I'm about to suggest will help but... Word will quite happily open (and edit) HTML directly. ie you can File > Open > http://timgolden.me.uk/python/index.html and the result will be an editable version of that webpage. What's not clear is whether this would serve your purpose or how you're getting the "formatted HTML" from your YUI editor to the Word doc, and whether it forms part of an existing doc. TJG From sharpblade1 at gmail.com Tue Jun 14 10:51:05 2011 From: sharpblade1 at gmail.com (sharpblade) Date: Tue, 14 Jun 2011 09:51:05 +0100 Subject: [python-win32] Converting HTML formatting to Microsoft Word In-Reply-To: <4DF7138F.9090107@timgolden.me.uk> References: <4DF7138F.9090107@timgolden.me.uk> Message-ID: Ah yes, sorry I didn't specify that. It is part of an existing doc: I have a Django web application with a Report model which contains information I need to put into a word document. Most of this is simple stuff requiring no formatting, and I achieve this by defining several bookmarks within the master template and populate them like so: doc.Bookmarks("prepared_for").Range.Text = job.customer.name doc.Bookmarks("reference_UTN").Range.Text = job.UTN doc.Bookmarks("test_type").Range.Text = job.get_type_display() This works fine, but there are several fields (An appendix for example) which may have text that needs to be formatted. The tl;dr of it is that I need to parse the HTML and format the text using a Range object accordingly. I whipped up this function: http://pastebin.com/kaZz5dBd which should work, but line 22 and 23 doesn't work for some reason - all text after it is bold. Anyone have any ideas? ~Tom On Tue, Jun 14, 2011 at 8:53 AM, Tim Golden wrote: > On 14/06/2011 00:20, Tom wrote: >> >> Hello, >> I have a Javascript rich text editor (Specifically the Yahoo UI >> libraries Simple Editor) which I have embedded within my web >> application. This produces formatted HTML from the users input which >> has to be placed within a Word document. >> The number of formatting options is limited - Bold, italics, >> underline, font size, font type, image insertion and lists. I thought >> this would be rather simple to automate using words COM interface, but >> I am having a lot of issues formatting the text using the COM >> interface - my solution so far parses the HTML using BeautifulSoup and >> rolls through each tag. If its a bold tag then it creates a range >> object at the end of the current one, inserts the bold text and sets >> the Bold attribute to True. >> >> My issue is that this doesn't work and produces confusing results - >> the text isn't formatted correctly and the Bold attribute is set to -1 >> (Which means a mix of both bold and non bold as far as I can tell). >> >> Does anyone have any experience doing anything similar to this, or can >> anyone give me a simpler way to do this? > > It's not 100% clear whether what I'm about to suggest will help but... > > Word will quite happily open (and edit) HTML directly. ie you can > > ?File > Open > http://timgolden.me.uk/python/index.html > > and the result will be an editable version of that webpage. > > What's not clear is whether this would serve your purpose or > how you're getting the "formatted HTML" from your YUI editor > to the Word doc, and whether it forms part of an existing > doc. > > TJG > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From cool_go_blue at yahoo.com Tue Jun 14 18:30:20 2011 From: cool_go_blue at yahoo.com (cool_go_blue) Date: Tue, 14 Jun 2011 09:30:20 -0700 (PDT) Subject: [python-win32] UnicodeEncodingError when print a doc file Message-ID: <244357.87334.qm@web43142.mail.sp1.yahoo.com> I try to read a word document as follows: app = win32com.client.Dispatch('Word.Application') doc = app.Documents.Open('D:\myfile.doc') print doc.Content.Text I receive the following error: raceback (most recent call last): ? File "D:\projects\Myself\MySVD\src\ReadWord.py", line 11, in ??? print doc.Content.Text ? File "D:\Softwares\Python27\lib\encodings\cp1252.py", line 12, in encode ??? return codecs.charmap_encode(input,errors,encoding_table) UnicodeEncodeError: 'charmap' codec can't encode character u'\uf06d' in position 4397: character maps to How can I fix the problem. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Tue Jun 14 19:36:01 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 14 Jun 2011 10:36:01 -0700 Subject: [python-win32] UnicodeEncodingError when print a doc file In-Reply-To: <244357.87334.qm@web43142.mail.sp1.yahoo.com> References: <244357.87334.qm@web43142.mail.sp1.yahoo.com> Message-ID: <4DF79C01.5050703@probo.com> cool_go_blue wrote: > I try to read a word document as follows: > > app = win32com.client.Dispatch('Word.Application') > doc = app.Documents.Open('D:\myfile.doc') > print doc.Content.Text > > I receive the following error: > > raceback (most recent call last): > File "D:\projects\Myself\MySVD\src\ReadWord.py", line 11, in > print doc.Content.Text > File "D:\Softwares\Python27\lib\encodings\cp1252.py", line 12, in encode > return codecs.charmap_encode(input,errors,encoding_table) > UnicodeEncodeError: 'charmap' codec can't encode character u'\uf06d' > in position 4397: character maps to > You are reading the Word document just fine. The issue is printing it to your terminal. The document contains Unicode characters that aren't present in your terminal's font. You need to tell it how to handle the conversion from Unicode to 8-bit. Try this: print doc.Content.Text.encode('cp1252','replace') That will print ? where invalid characters are found. U+F06D is not a valid character. It's in the "private use" area, so it's possible this is some special code to Word. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rays at blue-cove.com Tue Jun 14 20:34:25 2011 From: rays at blue-cove.com (RayS) Date: Tue, 14 Jun 2011 11:34:25 -0700 Subject: [python-win32] py2.7 and multiple DDE servers on Win32, possible? In-Reply-To: References: Message-ID: <20110614183431.RSZK17030.fed1rmfepo101.cox.net@fed1rmimpo01.cox.net> Ahh, this http://www.codeproject.com/KB/MFC/MFCinVisualStudioExpress.aspx might help. I'll work through it later... I do have VS6, but I'm assuming that I really need 2008 (?). Thanks, Ray At 10:13 PM 6/13/2011, Roger Upole wrote: >Compiling with VC 2008 Express is going to be a problem. The free >compiler doesn't seem to support using the atl/mfc headers and libraries. > > Roger -------------- next part -------------- An HTML attachment was scrubbed... URL: From cool_go_blue at yahoo.com Wed Jun 15 02:49:25 2011 From: cool_go_blue at yahoo.com (cool_go_blue) Date: Tue, 14 Jun 2011 17:49:25 -0700 (PDT) Subject: [python-win32] UnicodeEncodingError when print a doc file In-Reply-To: Message-ID: <521123.44108.qm@web43131.mail.sp1.yahoo.com> Thanks. It works. Actually, what I want to do is to parse the whole document. How can I retrieve the list of words in the document? I use the following code: for word in doc.Content.Text.encode("cp1252", "replace"): ??? print word It seems that word is each a character. How can I find API to process words in an open word document. Thanks. --- On Tue, 6/14/11, Preston Landers wrote: From: Preston Landers Subject: Re: [python-win32] UnicodeEncodingError when print a doc file To: "cool_go_blue" Date: Tuesday, June 14, 2011, 12:37 PM The document contains Unicode content that can't be rendered directly as the encoding cp1252 (Windows-1252) used by your console when you use the print statement. You can always write the content to a file in UTF-8 or UTF-16 and then view the file in a program like notepad that can handle Unicode.?I'm not sure if there's any way to get the Windows console to produce actual Unicode. If you absolutely must print this in the console, you can always substitute out unknown characters. ? print doc.Content.Text.encode("cp1252", "replace") Hope this helps,Preston On Tue, Jun 14, 2011 at 11:30 AM, cool_go_blue wrote: I try to read a word document as follows: app = win32com.client.Dispatch('Word.Application') doc = app.Documents.Open('D:\myfile.doc') print doc.Content.Text I receive the following error: raceback (most recent call last): ? File "D:\projects\Myself\MySVD\src\ReadWord.py", line 11, in ??? print doc.Content.Text ? File "D:\Softwares\Python27\lib\encodings\cp1252.py", line 12, in encode ??? return codecs.charmap_encode(input,errors,encoding_table) UnicodeEncodeError: 'charmap' codec can't encode character u'\uf06d' in position 4397: character maps to How can I fix the problem. Thanks. _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Wed Jun 15 03:02:06 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 14 Jun 2011 18:02:06 -0700 Subject: [python-win32] UnicodeEncodingError when print a doc file In-Reply-To: <521123.44108.qm@web43131.mail.sp1.yahoo.com> References: <521123.44108.qm@web43131.mail.sp1.yahoo.com> Message-ID: <4DF8048E.6020400@probo.com> cool_go_blue wrote: > Thanks. It works. Actually, what I want to do is to parse the whole > document. How can I retrieve the list of words in the > document? I use the following code: > > for word in doc.Content.Text.encode("cp1252", "replace"): > print word > > It seems that word is each a character. > No, what you are getting back is a Python string. When you enumerate through a string, you get characters. This is basic Python. If your words are all separated by spaces, you can use split: for word in doc.Content.Text.encode("cp1252","replace").split(): print word Note, however, that you don't need to convert it to an 8-bit character set until you want to print it. If you are going to process these words, then you might as well leave them in Unicode. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From cool_go_blue at yahoo.com Wed Jun 15 03:20:59 2011 From: cool_go_blue at yahoo.com (cool_go_blue) Date: Tue, 14 Jun 2011 18:20:59 -0700 (PDT) Subject: [python-win32] UnicodeEncodingError when print a doc file In-Reply-To: <4DF8048E.6020400@probo.com> Message-ID: <731230.99185.qm@web43140.mail.sp1.yahoo.com> Thanks. I just find that all item numbers such as 1.1.1 are gone. How can I get these numbers. Also, If all items are in a table, how can I get the contents of all items and ignore the table structure. Thanks. --- On Tue, 6/14/11, Tim Roberts wrote: From: Tim Roberts Subject: Re: [python-win32] UnicodeEncodingError when print a doc file To: "python-win32 at python.org" Date: Tuesday, June 14, 2011, 9:02 PM cool_go_blue wrote: > Thanks. It works. Actually, what I want to do is to parse the whole > document. How can I retrieve the list of words in the > document? I use the following code: > > for word in doc.Content.Text.encode("cp1252", "replace"): >? ???print word > > It seems that word is each a character. > No, what you are getting back is a Python string.? When you enumerate through a string, you get characters.? This is basic Python. If your words are all separated by spaces, you can use split: ? ? for word in doc.Content.Text.encode("cp1252","replace").split(): ? ? ? ? print word Note, however, that you don't need to convert it to an 8-bit character set until you want to print it.? If you are going to process these words, then you might as well leave them in Unicode. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- An HTML attachment was scrubbed... URL: From planders at gmail.com Wed Jun 15 04:08:48 2011 From: planders at gmail.com (Preston Landers) Date: Tue, 14 Jun 2011 21:08:48 -0500 Subject: [python-win32] UnicodeEncodingError when print a doc file In-Reply-To: <731230.99185.qm@web43140.mail.sp1.yahoo.com> References: <4DF8048E.6020400@probo.com> <731230.99185.qm@web43140.mail.sp1.yahoo.com> Message-ID: I think you'll have to get into the guts of the Document object to do things like that. Here's the official Word 2007 object model documentation. Any tutorials or examples you can find that use other languages like C# or VB.NET would be relevant, you just have to translate them a bit to Python. The underlying Document API is the same across languages. http://msdn.microsoft.com/en-us/library/bb243297(v=office.12).aspx On Tue, Jun 14, 2011 at 8:20 PM, cool_go_blue wrote: > Thanks. I just find that all item numbers such as 1.1.1 are gone. How can I > get these numbers. Also, If all items are in a table, how can I get the > contents of all items and ignore the table structure. Thanks. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Wed Jun 15 12:15:46 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 15 Jun 2011 20:15:46 +1000 Subject: [python-win32] py2.7 and multiple DDE servers on Win32, possible? In-Reply-To: <20110610171910.GPJC16474.fed1rmfepo201.cox.net@fed1rmimpo01.cox.net> References: <20110610171910.GPJC16474.fed1rmfepo201.cox.net@fed1rmimpo01.cox.net> Message-ID: <4DF88652.2070508@gmail.com> On 11/06/2011 3:19 AM, RayS wrote: > Hello > > I know that the default behavior since 2.? has been only one DDE server > allowed. > Is it possible to back-hack this restriction? It is possible, yeah - it's just a matter of someone doing it :) Cheers, Mark From skippy.hammond at gmail.com Wed Jun 15 12:20:04 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 15 Jun 2011 20:20:04 +1000 Subject: [python-win32] py2.7 and multiple DDE servers on Win32, possible? In-Reply-To: <4DF88652.2070508@gmail.com> References: <20110610171910.GPJC16474.fed1rmfepo201.cox.net@fed1rmimpo01.cox.net> <4DF88652.2070508@gmail.com> Message-ID: <4DF88754.2070001@gmail.com> On 15/06/2011 8:15 PM, Mark Hammond wrote: > On 11/06/2011 3:19 AM, RayS wrote: >> Hello >> >> I know that the default behavior since 2.? has been only one DDE server >> allowed. >> Is it possible to back-hack this restriction? > > It is possible, yeah - it's just a matter of someone doing it :) Oops - sorry - I misunderstood the question... Mark From skippy.hammond at gmail.com Wed Jun 15 12:35:51 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 15 Jun 2011 20:35:51 +1000 Subject: [python-win32] Creating PyCComboBox? In-Reply-To: <4DF31170.6040600@canterbury.ac.nz> References: <4DF31170.6040600@canterbury.ac.nz> Message-ID: <4DF88B07.4040108@gmail.com> On 11/06/2011 4:55 PM, Greg Ewing wrote: > How are you supposed to create a PyCComboBox? There > doesn't seem to be a CreateComboBox function anywhere. > > I tried using CreateControl("COMBOBOX", ...) but it > says that the CLSID is invalid. I think you just want a CreateWindow(Ex) with "Combobox" as the class. Mark From skippy.hammond at gmail.com Wed Jun 15 12:46:28 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 15 Jun 2011 20:46:28 +1000 Subject: [python-win32] Telit PhytonWin In-Reply-To: References: Message-ID: <4DF88D84.2010103@gmail.com> On 13/06/2011 10:00 PM, Famacoin wrote: > Hi > We have a problem loading script for the GM862-GPS module over 7k when > we try to load gives ERROR IN THE DOWNLOAD, and sometimes says OK but > does not load the entire file, we have checked the serial port but do > not get the fault?. I'm afraid I have no idea what that GPS module is - you might have more luck if you copy and pasted the exact problem you have. > Do not know if there is a newer version that we have is Telit PythonWin > 1.5.2+ (#0, Oct 1 2004, 15:39:52) Python 1.5.2 is extremely old. You should upgrade to a newer Python then grab a new pywin32 for that version. Cheers, Mark From skippy.hammond at gmail.com Wed Jun 15 12:51:28 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 15 Jun 2011 20:51:28 +1000 Subject: [python-win32] Converting HTML formatting to Microsoft Word In-Reply-To: References: <4DF7138F.9090107@timgolden.me.uk> Message-ID: <4DF88EB0.50504@gmail.com> On 14/06/2011 6:51 PM, sharpblade wrote: > I whipped up this function: http://pastebin.com/kaZz5dBd which should > work, but line 22 and 23 doesn't work for some reason - all text after > it is bold. The last thing you do in those lines is set the range to bold - presumably later you then insert more text right at the end of the range - maybe word is just keeping the bold for the new text just like it would do if you where typing (ie, IIRC, if the cursor is at the end of a bold range, new text you type is also bold...) Or not - just a thought :) Mark From Tom.Hawkins at innospecinc.com Wed Jun 15 13:57:58 2011 From: Tom.Hawkins at innospecinc.com (Tom Hawkins) Date: Wed, 15 Jun 2011 12:57:58 +0100 Subject: [python-win32] UnicodeEncodingError when print a doc file Message-ID: <80EF6E679A466046BA07D071932847B32325B5@UKEPX101.innospec.itnet.octel> >Thanks. I just find that all item numbers such as 1.1.1 are gone. How can I get these >numbers. Also, If all items are in a table, how can I get the contents of all items and >ignore the table structure. Thanks. If you have auto-numbered paragraphs then I'd guess the numbers are generated by Word as part of formatting the text for display and aren't part of the literal text of the document. Could you programatically or manually save the Word doc as plain text and analyse the text file? That will get you the paragraph numbers as text (at least it worked for me just now in a quick test on Word 2003) and might solve your table issue as well. Tom Hawkins Principal Scientist Innospec Inc Tel: +44 (0)151 356 6197 Fax: +44 (0)151 356 6112 -----Original Message----- From: python-win32-bounces+tom.hawkins=innospecinc.com at python.org [mailto:python-win32-bounces+tom.hawkins=innospecinc.com at python.org] On Behalf Of python-win32-request at python.org Sent: 15 June 2011 02:21 To: python-win32 at python.org Subject: python-win32 Digest, Vol 99, Issue 13 Send python-win32 mailing list submissions to python-win32 at python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/python-win32 or, via email, send a message with subject or body 'help' to python-win32-request at python.org You can reach the person managing the list at python-win32-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of python-win32 digest..." Today's Topics: 1. UnicodeEncodingError when print a doc file (cool_go_blue) 2. Re: UnicodeEncodingError when print a doc file (Tim Roberts) 3. Re: py2.7 and multiple DDE servers on Win32, possible? (RayS) 4. Re: UnicodeEncodingError when print a doc file (cool_go_blue) 5. Re: UnicodeEncodingError when print a doc file (Tim Roberts) 6. Re: UnicodeEncodingError when print a doc file (cool_go_blue) ---------------------------------------------------------------------- Message: 1 Date: Tue, 14 Jun 2011 09:30:20 -0700 (PDT) From: cool_go_blue To: python-win32 at python.org Subject: [python-win32] UnicodeEncodingError when print a doc file Message-ID: <244357.87334.qm at web43142.mail.sp1.yahoo.com> Content-Type: text/plain; charset="iso-8859-1" I try to read a word document as follows: app = win32com.client.Dispatch('Word.Application') doc = app.Documents.Open('D:\myfile.doc') print doc.Content.Text I receive the following error: raceback (most recent call last): ? File "D:\projects\Myself\MySVD\src\ReadWord.py", line 11, in ??? print doc.Content.Text ? File "D:\Softwares\Python27\lib\encodings\cp1252.py", line 12, in encode ??? return codecs.charmap_encode(input,errors,encoding_table) UnicodeEncodeError: 'charmap' codec can't encode character u'\uf06d' in position 4397: character maps to How can I fix the problem. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: ------------------------------ Message: 2 Date: Tue, 14 Jun 2011 10:36:01 -0700 From: Tim Roberts To: Python-Win32 List Subject: Re: [python-win32] UnicodeEncodingError when print a doc file Message-ID: <4DF79C01.5050703 at probo.com> Content-Type: text/plain; charset="ISO-8859-1" cool_go_blue wrote: > I try to read a word document as follows: > > app = win32com.client.Dispatch('Word.Application') > doc = app.Documents.Open('D:\myfile.doc') > print doc.Content.Text > > I receive the following error: > > raceback (most recent call last): > File "D:\projects\Myself\MySVD\src\ReadWord.py", line 11, in > print doc.Content.Text > File "D:\Softwares\Python27\lib\encodings\cp1252.py", line 12, in encode > return codecs.charmap_encode(input,errors,encoding_table) > UnicodeEncodeError: 'charmap' codec can't encode character u'\uf06d' > in position 4397: character maps to > You are reading the Word document just fine. The issue is printing it to your terminal. The document contains Unicode characters that aren't present in your terminal's font. You need to tell it how to handle the conversion from Unicode to 8-bit. Try this: print doc.Content.Text.encode('cp1252','replace') That will print ? where invalid characters are found. U+F06D is not a valid character. It's in the "private use" area, so it's possible this is some special code to Word. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. ------------------------------ Message: 3 Date: Tue, 14 Jun 2011 11:34:25 -0700 From: RayS To: Subject: Re: [python-win32] py2.7 and multiple DDE servers on Win32, possible? Message-ID: <20110614183431.RSZK17030.fed1rmfepo101.cox.net at fed1rmimpo01.cox.net> Content-Type: text/plain; charset="us-ascii"; Format="flowed" Ahh, this http://www.codeproject.com/KB/MFC/MFCinVisualStudioExpress.aspx might help. I'll work through it later... I do have VS6, but I'm assuming that I really need 2008 (?). Thanks, Ray At 10:13 PM 6/13/2011, Roger Upole wrote: >Compiling with VC 2008 Express is going to be a problem. The free >compiler doesn't seem to support using the atl/mfc headers and libraries. > > Roger -------------- next part -------------- An HTML attachment was scrubbed... URL: ------------------------------ Message: 4 Date: Tue, 14 Jun 2011 17:49:25 -0700 (PDT) From: cool_go_blue To: python-win32 at python.org Subject: Re: [python-win32] UnicodeEncodingError when print a doc file Message-ID: <521123.44108.qm at web43131.mail.sp1.yahoo.com> Content-Type: text/plain; charset="iso-8859-1" Thanks. It works. Actually, what I want to do is to parse the whole document. How can I retrieve the list of words in the document? I use the following code: for word in doc.Content.Text.encode("cp1252", "replace"): ??? print word It seems that word is each a character. How can I find API to process words in an open word document. Thanks. --- On Tue, 6/14/11, Preston Landers wrote: From: Preston Landers Subject: Re: [python-win32] UnicodeEncodingError when print a doc file To: "cool_go_blue" Date: Tuesday, June 14, 2011, 12:37 PM The document contains Unicode content that can't be rendered directly as the encoding cp1252 (Windows-1252) used by your console when you use the print statement. You can always write the content to a file in UTF-8 or UTF-16 and then view the file in a program like notepad that can handle Unicode.?I'm not sure if there's any way to get the Windows console to produce actual Unicode. If you absolutely must print this in the console, you can always substitute out unknown characters. ? print doc.Content.Text.encode("cp1252", "replace") Hope this helps,Preston On Tue, Jun 14, 2011 at 11:30 AM, cool_go_blue wrote: I try to read a word document as follows: app = win32com.client.Dispatch('Word.Application') doc = app.Documents.Open('D:\myfile.doc') print doc.Content.Text I receive the following error: raceback (most recent call last): ? File "D:\projects\Myself\MySVD\src\ReadWord.py", line 11, in ??? print doc.Content.Text ? File "D:\Softwares\Python27\lib\encodings\cp1252.py", line 12, in encode ??? return codecs.charmap_encode(input,errors,encoding_table) UnicodeEncodeError: 'charmap' codec can't encode character u'\uf06d' in position 4397: character maps to How can I fix the problem. Thanks. _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- An HTML attachment was scrubbed... URL: ------------------------------ Message: 5 Date: Tue, 14 Jun 2011 18:02:06 -0700 From: Tim Roberts To: "python-win32 at python.org" Subject: Re: [python-win32] UnicodeEncodingError when print a doc file Message-ID: <4DF8048E.6020400 at probo.com> Content-Type: text/plain; charset="ISO-8859-1" cool_go_blue wrote: > Thanks. It works. Actually, what I want to do is to parse the whole > document. How can I retrieve the list of words in the > document? I use the following code: > > for word in doc.Content.Text.encode("cp1252", "replace"): > print word > > It seems that word is each a character. > No, what you are getting back is a Python string. When you enumerate through a string, you get characters. This is basic Python. If your words are all separated by spaces, you can use split: for word in doc.Content.Text.encode("cp1252","replace").split(): print word Note, however, that you don't need to convert it to an 8-bit character set until you want to print it. If you are going to process these words, then you might as well leave them in Unicode. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. ------------------------------ Message: 6 Date: Tue, 14 Jun 2011 18:20:59 -0700 (PDT) From: cool_go_blue To: "python-win32 at python.org" Subject: Re: [python-win32] UnicodeEncodingError when print a doc file Message-ID: <731230.99185.qm at web43140.mail.sp1.yahoo.com> Content-Type: text/plain; charset="iso-8859-1" Thanks. I just find that all item numbers such as 1.1.1 are gone. How can I get these numbers. Also, If all items are in a table, how can I get the contents of all items and ignore the table structure. Thanks. --- On Tue, 6/14/11, Tim Roberts wrote: From: Tim Roberts Subject: Re: [python-win32] UnicodeEncodingError when print a doc file To: "python-win32 at python.org" Date: Tuesday, June 14, 2011, 9:02 PM cool_go_blue wrote: > Thanks. It works. Actually, what I want to do is to parse the whole > document. How can I retrieve the list of words in the > document? I use the following code: > > for word in doc.Content.Text.encode("cp1252", "replace"): >? ???print word > > It seems that word is each a character. > No, what you are getting back is a Python string.? When you enumerate through a string, you get characters.? This is basic Python. If your words are all separated by spaces, you can use split: ? ? for word in doc.Content.Text.encode("cp1252","replace").split(): ? ? ? ? print word Note, however, that you don't need to convert it to an 8-bit character set until you want to print it.? If you are going to process these words, then you might as well leave them in Unicode. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- An HTML attachment was scrubbed... URL: ------------------------------ _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 End of python-win32 Digest, Vol 99, Issue 13 ******************************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: From sharpblade1 at gmail.com Wed Jun 15 14:13:49 2011 From: sharpblade1 at gmail.com (sharpblade) Date: Wed, 15 Jun 2011 13:13:49 +0100 Subject: [python-win32] Converting HTML formatting to Microsoft Word In-Reply-To: <4DF88EB0.50504@gmail.com> References: <4DF7138F.9090107@timgolden.me.uk> <4DF88EB0.50504@gmail.com> Message-ID: Heh, thanks! I dreamed of writing some nice recursive function, but I gave up and moved to the HTMLParser module: http://paste.pocoo.org/show/408125/ Its WIP at the moment but works nicely with bold, underline, italics and bulletpoint lists. It was a lot nicer and more concise before I found out that the WYSIWYG editor also outputs to format text as well as and , so i'm hacking away at it to get it to work with those. On Wed, Jun 15, 2011 at 11:51 AM, Mark Hammond wrote: > On 14/06/2011 6:51 PM, sharpblade wrote: >> >> I whipped up this function: http://pastebin.com/kaZz5dBd which should >> work, but line 22 and 23 doesn't work for some reason - all text after >> it is bold. > > The last thing you do in those lines is set the range to bold - presumably > later you then insert more text right at the end of the range - maybe word > is just keeping the bold for the new text just like it would do if you where > typing (ie, IIRC, if the cursor is at the end of a bold range, new text you > type is also bold...) > > Or not - just a thought :) > > Mark > From jacobk at mailzone.co.za Wed Jun 15 14:51:13 2011 From: jacobk at mailzone.co.za (Jacob Kruger) Date: Wed, 15 Jun 2011 14:51:13 +0200 Subject: [python-win32] Generic/simple way to make backups of objects/their states? Message-ID: I know I can do a version of manual import/export process to do something like either backup all relevant attributes of some or other object to something like a CSV, or XML string rendition, and then save that to a file easily enough, but just wondering if there's any simpler way to render an object/class instance to a string rendition, and then to maybe reiterate the original object later on..? TIA (and not too important, but just wondering) Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' From mail at timgolden.me.uk Wed Jun 15 15:01:05 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 15 Jun 2011 14:01:05 +0100 Subject: [python-win32] Generic/simple way to make backups of objects/their states? In-Reply-To: References: Message-ID: <4DF8AD11.5030909@timgolden.me.uk> On 15/06/2011 13:51, Jacob Kruger wrote: > I know I can do a version of manual import/export process to do > something like either backup all relevant attributes of some or other > object to something like a CSV, or XML string rendition, and then > save that to a file easily enough, but just wondering if there's any > simpler way to render an object/class instance to a string rendition, > and then to maybe reiterate the original object later on..? > > TIA (and not too important, but just wondering) The standard Python way is the pickle module: http://docs.python.org/library/pickle.html If your objects are very simple (basically core Python objects) then marshal is lighter and faster: http://docs.python.org/library/marshal.html There are definitely other options out there. The stdlib has recently included JSON support: http://docs.python.org/library/json.html and there are definitely third-party options as well. Just Google for "python object serialisation" or something. TJG From cool_go_blue at yahoo.com Wed Jun 15 16:16:17 2011 From: cool_go_blue at yahoo.com (cool_go_blue) Date: Wed, 15 Jun 2011 07:16:17 -0700 (PDT) Subject: [python-win32] UnicodeEncodingError when print a doc file In-Reply-To: <80EF6E679A466046BA07D071932847B32325B5@UKEPX101.innospec.itnet.octel> Message-ID: <668505.40166.qm@web43142.mail.sp1.yahoo.com> Thanks for your suggestion,? Tom. Yes.I think it's an auto-number paragraph. How can I auto programatically save the word file in Python? The manual save means I copy and paste to a wordpad file, right? --- On Wed, 6/15/11, Tom Hawkins wrote: From: Tom Hawkins Subject: Re: [python-win32] UnicodeEncodingError when print a doc file To: python-win32 at python.org Date: Wednesday, June 15, 2011, 7:57 AM >Thanks. I just find that all item numbers such as 1.1.1 are gone. How can I get these >numbers. Also, If all items are in a table, how can I get the contents of all items and >ignore the table structure. Thanks. ? If you have auto-numbered paragraphs then I?d guess the numbers are generated by Word as part of formatting the text for display and aren?t part of the literal text of the document. ? Could you programatically or manually save the Word doc as plain text and analyse the text file? That will get you the paragraph numbers as text (at least it worked for me just now in a quick test on Word 2003) and might solve your table issue as well. ? Tom Hawkins Principal Scientist Innospec Inc Tel: +44 (0)151 356 6197 Fax: +44 (0)151 356 6112 ? -----Original Message----- From: python-win32-bounces+tom.hawkins=innospecinc.com at python.org [mailto:python-win32-bounces+tom.hawkins=innospecinc.com at python.org] On Behalf Of python-win32-request at python.org Sent: 15 June 2011 02:21 To: python-win32 at python.org Subject: python-win32 Digest, Vol 99, Issue 13 ? Send python-win32 mailing list submissions to ????????? python-win32 at python.org ? To subscribe or unsubscribe via the World Wide Web, visit ????????? http://mail.python.org/mailman/listinfo/python-win32 or, via email, send a message with subject or body 'help' to ????????? python-win32-request at python.org ? You can reach the person managing the list at ????????? python-win32-owner at python.org ? When replying, please edit your Subject line so it is more specific than "Re: Contents of python-win32 digest..." ? ? Today's Topics: ? ?? 1. UnicodeEncodingError when print a doc file (cool_go_blue) ?? 2. Re: UnicodeEncodingError when print a doc file (Tim Roberts) ?? 3. Re: py2.7 and multiple DDE servers on Win32, possible? (RayS) ?? 4. Re: UnicodeEncodingError when print a doc file (cool_go_blue) ?? 5. Re: UnicodeEncodingError when print a doc file (Tim Roberts) ?? 6. Re: UnicodeEncodingError when print a doc file (cool_go_blue) ? ? ---------------------------------------------------------------------- ? Message: 1 Date: Tue, 14 Jun 2011 09:30:20 -0700 (PDT) From: cool_go_blue To: python-win32 at python.org Subject: [python-win32] UnicodeEncodingError when print a doc file Message-ID: <244357.87334.qm at web43142.mail.sp1.yahoo.com> Content-Type: text/plain; charset="iso-8859-1" ? I try to read a word document as follows: ? ? ????????? ? ????????? ? app = win32com.client.Dispatch('Word.Application') doc = app.Documents.Open('D:\myfile.doc') print doc.Content.Text ? I receive the following error: ? raceback (most recent call last): ? File "D:\projects\Myself\MySVD\src\ReadWord.py", line 11, in ??? print doc.Content.Text ? File "D:\Softwares\Python27\lib\encodings\cp1252.py", line 12, in encode ??? return codecs.charmap_encode(input,errors,encoding_table) UnicodeEncodeError: 'charmap' codec can't encode character u'\uf06d' in position 4397: character maps to ? How can I fix the problem. Thanks. ? ? -------------- next part -------------- An HTML attachment was scrubbed... URL: ? ------------------------------ ? Message: 2 Date: Tue, 14 Jun 2011 10:36:01 -0700 From: Tim Roberts To: Python-Win32 List Subject: Re: [python-win32] UnicodeEncodingError when print a doc file Message-ID: <4DF79C01.5050703 at probo.com> Content-Type: text/plain; charset="ISO-8859-1" ? cool_go_blue wrote: > I try to read a word document as follows: > ? > app = win32com.client.Dispatch('Word.Application') > doc = app.Documents.Open('D:\myfile.doc') > print doc.Content.Text > ? > I receive the following error: > ? > raceback (most recent call last): >?? File "D:\projects\Myself\MySVD\src\ReadWord.py", line 11, in >???? print doc.Content.Text >?? File "D:\Softwares\Python27\lib\encodings\cp1252.py", line 12, in encode >???? return codecs.charmap_encode(input,errors,encoding_table) > UnicodeEncodeError: 'charmap' codec can't encode character u'\uf06d' > in position 4397: character maps to > ? ? You are reading the Word document just fine.? The issue is printing it to your terminal.? The document contains Unicode characters that aren't present in your terminal's font.? You need to tell it how to handle the conversion from Unicode to 8-bit.? Try this: ? ??? print doc.Content.Text.encode('cp1252','replace') ? That will print ? where invalid characters are found. ? U+F06D is not a valid character.? It's in the "private use" area, so it's possible this is some special code to Word. ? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. ? ? ? ------------------------------ ? Message: 3 Date: Tue, 14 Jun 2011 11:34:25 -0700 From: RayS To: Subject: Re: [python-win32] py2.7 and multiple DDE servers on Win32, ????????? possible? Message-ID: ????????? <20110614183431.RSZK17030.fed1rmfepo101.cox.net at fed1rmimpo01.cox.net> Content-Type: text/plain; charset="us-ascii"; Format="flowed" ? Ahh, this http://www.codeproject.com/KB/MFC/MFCinVisualStudioExpress.aspx might help. I'll work through it later... I do have VS6, but I'm assuming that I really need 2008 (?). ? Thanks, Ray ? At 10:13 PM 6/13/2011, Roger Upole wrote: >Compiling with VC 2008 Express is going to be a problem.? The free >compiler doesn't seem to support using the atl/mfc headers and libraries. > ? >????????? Roger -------------- next part -------------- An HTML attachment was scrubbed... URL: ? ------------------------------ ? Message: 4 Date: Tue, 14 Jun 2011 17:49:25 -0700 (PDT) From: cool_go_blue To: python-win32 at python.org Subject: Re: [python-win32] UnicodeEncodingError when print a doc file Message-ID: <521123.44108.qm at web43131.mail.sp1.yahoo.com> Content-Type: text/plain; charset="iso-8859-1" ? Thanks. It works. Actually, what I want to do is to parse the whole document. How can I retrieve the list of words in the document? I use the following code: ? for word in doc.Content.Text.encode("cp1252", "replace"): ??? print word ? It seems that word is each a character. How can I find API to process words in an open word document. Thanks. ? ? --- On Tue, 6/14/11, Preston Landers wrote: ? From: Preston Landers Subject: Re: [python-win32] UnicodeEncodingError when print a doc file To: "cool_go_blue" Date: Tuesday, June 14, 2011, 12:37 PM ? The document contains Unicode content that can't be rendered directly as the encoding cp1252 (Windows-1252) used by your console when you use the print statement. You can always write the content to a file in UTF-8 or UTF-16 and then view the file in a program like notepad that can handle Unicode.?I'm not sure if there's any way to get the Windows console to produce actual Unicode. ? ? If you absolutely must print this in the console, you can always substitute out unknown characters. ? print doc.Content.Text.encode("cp1252", "replace") ? ? Hope this helps, Preston On Tue, Jun 14, 2011 at 11:30 AM, cool_go_blue wrote: ? ? I try to read a word document as follows: ? ? ? ? ????????? ? ????????? ? app = win32com.client.Dispatch('Word.Application') doc = app.Documents.Open('D:\myfile.doc') print doc.Content.Text ? I receive the following error: ? ? ? raceback (most recent call last): ? File "D:\projects\Myself\MySVD\src\ReadWord.py", line 11, in ??? print doc.Content.Text ? File "D:\Softwares\Python27\lib\encodings\cp1252.py", line 12, in encode ? ? ??? return codecs.charmap_encode(input,errors,encoding_table) UnicodeEncodeError: 'charmap' codec can't encode character u'\uf06d' in position 4397: character maps to ? How can I fix the problem. Thanks. ? ? ? ? ? _______________________________________________ ? python-win32 mailing list ? python-win32 at python.org ? http://mail.python.org/mailman/listinfo/python-win32 ? ? ? ? -------------- next part -------------- An HTML attachment was scrubbed... URL: ? ------------------------------ ? Message: 5 Date: Tue, 14 Jun 2011 18:02:06 -0700 From: Tim Roberts To: "python-win32 at python.org" Subject: Re: [python-win32] UnicodeEncodingError when print a doc file Message-ID: <4DF8048E.6020400 at probo.com> Content-Type: text/plain; charset="ISO-8859-1" ? cool_go_blue wrote: > Thanks. It works. Actually, what I want to do is to parse the whole > document. How can I retrieve the list of words in the > document? I use the following code: > ? > for word in doc.Content.Text.encode("cp1252", "replace"): >???? print word > ? > It seems that word is each a character. > ? ? No, what you are getting back is a Python string.? When you enumerate through a string, you get characters.? This is basic Python. ? If your words are all separated by spaces, you can use split: ? ??? for word in doc.Content.Text.encode("cp1252","replace").split(): ??????? print word ? Note, however, that you don't need to convert it to an 8-bit character set until you want to print it.? If you are going to process these words, then you might as well leave them in Unicode. ? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. ? ? ? ------------------------------ ? Message: 6 Date: Tue, 14 Jun 2011 18:20:59 -0700 (PDT) From: cool_go_blue To: "python-win32 at python.org" Subject: Re: [python-win32] UnicodeEncodingError when print a doc file Message-ID: <731230.99185.qm at web43140.mail.sp1.yahoo.com> Content-Type: text/plain; charset="iso-8859-1" ? Thanks. I just find that all item numbers such as 1.1.1 are gone. How can I get these numbers. Also, If all items are in a table, how can I get the contents of all items and ignore the table structure. Thanks. ? --- On Tue, 6/14/11, Tim Roberts wrote: ? From: Tim Roberts Subject: Re: [python-win32] UnicodeEncodingError when print a doc file To: "python-win32 at python.org" Date: Tuesday, June 14, 2011, 9:02 PM ? cool_go_blue wrote: > Thanks. It works. Actually, what I want to do is to parse the whole > document. How can I retrieve the list of words in the > document? I use the following code: > ? > for word in doc.Content.Text.encode("cp1252", "replace"): >? ???print word > ? > It seems that word is each a character. > ? ? No, what you are getting back is a Python string.? When you enumerate through a string, you get characters.? This is basic Python. ? If your words are all separated by spaces, you can use split: ? ? ? for word in doc.Content.Text.encode("cp1252","replace").split(): ? ? ? ? print word ? Note, however, that you don't need to convert it to an 8-bit character set until you want to print it.? If you are going to process these words, then you might as well leave them in Unicode. ? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. ? _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- An HTML attachment was scrubbed... URL: ? ------------------------------ ? _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 ? ? End of python-win32 Digest, Vol 99, Issue 13 ******************************************** -----Inline Attachment Follows----- _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- An HTML attachment was scrubbed... URL: From Tom.Hawkins at innospecinc.com Wed Jun 15 16:30:32 2011 From: Tom.Hawkins at innospecinc.com (Tom Hawkins) Date: Wed, 15 Jun 2011 15:30:32 +0100 Subject: [python-win32] UnicodeEncodingError when print a doc file Message-ID: <80EF6E679A466046BA07D071932847B32325B9@UKEPX101.innospec.itnet.octel> By 'manually' I mean choosing the File->Save As menu item and changing 'Save as type' to Plain Text. I'm not familiar with how to automate it directly from Python, but in Word VBA you would use something like: ActiveDocument.SaveAs FileName:="myfile.txt", FileFormat:=wdFormatText Again these examples are for Word 2003. PS Profuse apologies for quoting the entire digest in my last message! Tom Hawkins Principal Scientist Innospec Inc Tel: +44 (0)151 356 6197 Fax: +44 (0)151 356 6112 -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 791 bytes Desc: image001.jpg URL: From cool_go_blue at yahoo.com Wed Jun 15 16:44:26 2011 From: cool_go_blue at yahoo.com (cool_go_blue) Date: Wed, 15 Jun 2011 07:44:26 -0700 (PDT) Subject: [python-win32] UnicodeEncodingError when print a doc file In-Reply-To: Message-ID: <307459.53636.qm@web43142.mail.sp1.yahoo.com> Thanks. I clicked on the following link and I get lost about how to find APIs. I think I need to go to the following page: http://msdn.microsoft.com/en-us/library/bb225019%28v=office.12%29.aspx to find APIs. To read an auto-number paragraph, I check: word Document Object Map and find paragraph. But what API should I use to read all words and the auto-number of this paragraph. It seems a huge table in each object map. Thanks. -- On Tue, 6/14/11, Preston Landers wrote From: Preston Landers Subject: Re: [python-win32] UnicodeEncodingError when print a doc file To: "cool_go_blue" Cc: "python-win32 at python.org" Date: Tuesday, June 14, 2011, 10:08 PM I think you'll have to get into the guts of the Document object to do things like that. ?Here's the official?Word 2007 object model documentation. Any tutorials or examples you can find that use other languages like C# or VB.NET would be relevant, you just have to translate them a bit to Python. ?The underlying Document API is the same across languages. http://msdn.microsoft.com/en-us/library/bb243297(v=office.12).aspx On Tue, Jun 14, 2011 at 8:20 PM, cool_go_blue wrote: Thanks. I just find that all item numbers such as 1.1.1 are gone. How can I get these numbers. Also, If all items are in a table, how can I get the contents of all items and ignore the table structure. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Wed Jun 15 16:50:32 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 15 Jun 2011 15:50:32 +0100 Subject: [python-win32] UnicodeEncodingError when print a doc file In-Reply-To: <80EF6E679A466046BA07D071932847B32325B9@UKEPX101.innospec.itnet.octel> References: <80EF6E679A466046BA07D071932847B32325B9@UKEPX101.innospec.itnet.octel> Message-ID: <4DF8C6B8.9080403@timgolden.me.uk> On 15/06/2011 15:30, Tom Hawkins wrote: > By ?manually? I mean choosing the File->Save As menu item and changing > ?Save as type? to Plain Text. > > I?m not familiar with how to automate it directly from Python, but in > Word VBA you would use something like: > > ActiveDocument.SaveAs FileName:="myfile.txt", FileFormat:=wdFormatText .. and for anyone who couldn't guess, in Python that would be something like: ActiveDocument.SaveAs ( FileName="myfile.txt", FileFormat=win32com.client.constants.wdFormatText ) TJG From cool_go_blue at yahoo.com Wed Jun 15 17:11:18 2011 From: cool_go_blue at yahoo.com (cool_go_blue) Date: Wed, 15 Jun 2011 08:11:18 -0700 (PDT) Subject: [python-win32] UnicodeEncodingError when print a doc file In-Reply-To: <4DF8C6B8.9080403@timgolden.me.uk> Message-ID: <815735.65110.qm@web43142.mail.sp1.yahoo.com> I did try the one you suggest. But I got: ? File "D:\projects\Myself\MySVD\src\ReadWord.py", line 11, in ??? app.ActiveDocument.SaveAs('D:\projects\Myself\HelloPython\src\Drugreservoir1.txt',FileFormat=win32com.client.constants.wdFormatText) ? File "D:\Softwares\Python27\lib\site-packages\win32com\client\__init__.py", line 170, in __getattr__ ??? raise AttributeError(a) AttributeError: wdFormatText Also I replace wdFormatText with wdFormatTextLineBreaks. Same error... --- On Wed, 6/15/11, Tim Golden wrote: From: Tim Golden Subject: Re: [python-win32] UnicodeEncodingError when print a doc file To: Cc: python-win32 at python.org Date: Wednesday, June 15, 2011, 10:50 AM On 15/06/2011 15:30, Tom Hawkins wrote: > By ?manually? I mean choosing the File->Save As menu item and changing > ?Save as type? to Plain Text. > > I?m not familiar with how to automate it directly from Python, but in > Word VBA you would use something like: > > ActiveDocument.SaveAs FileName:="myfile.txt", FileFormat:=wdFormatText .. and for anyone who couldn't guess, in Python that would be something like: ActiveDocument.SaveAs ( ???FileName="myfile.txt", FileFormat=win32com.client.constants.wdFormatText ) TJG _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Wed Jun 15 19:10:05 2011 From: timr at probo.com (Tim Roberts) Date: Wed, 15 Jun 2011 10:10:05 -0700 Subject: [python-win32] UnicodeEncodingError when print a doc file In-Reply-To: <815735.65110.qm@web43142.mail.sp1.yahoo.com> References: <815735.65110.qm@web43142.mail.sp1.yahoo.com> Message-ID: <4DF8E76D.9060503@probo.com> cool_go_blue wrote: > I did try the one you suggest. But I got: > > File "D:\projects\Myself\MySVD\src\ReadWord.py", line 11, in > > app.ActiveDocument.SaveAs('D:\projects\Myself\HelloPython\src\Drugreservoir1.txt',FileFormat=win32com.client.constants.wdFormatText) > File > "D:\Softwares\Python27\lib\site-packages\win32com\client\__init__.py", > line 170, in __getattr__ > raise AttributeError(a) > AttributeError: wdFormatText > > Also I replace wdFormatText with wdFormatTextLineBreaks. Same error... > How are you creating your Word object? The Dispatch process should import these constants for you. In any case, 15 seconds with Google would have showed you that wdFormatText = 2 and wdFormatTextLineBreaks = 3. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Wed Jun 15 21:26:31 2011 From: timr at probo.com (Tim Roberts) Date: Wed, 15 Jun 2011 12:26:31 -0700 Subject: [python-win32] UnicodeEncodingError when print a doc file In-Reply-To: <383957.4735.qm@web43138.mail.sp1.yahoo.com> References: <383957.4735.qm@web43138.mail.sp1.yahoo.com> Message-ID: <4DF90767.9040802@probo.com> cool_go_blue wrote: > this is the first three lines of my code: > > app = win32com.client.Dispatch('Word.Application') > app.Documents.Open('D:\projects\Myself\HelloPython\src\Drugreservoir.doc') > app.ActiveDocument.SaveAs('D:\projects\Myself\HelloPython\src\Drugreservoir1.txt',FileFormat=win32com.client.constants.wdFormatText) > If you use this instead: app = win32com.client.gencache.EnsureDispatch('Word.Application') then the framework will build a Python wrapper for objects of that type, and that Python wrapper will create the constants. You MUST get in the habit of using the proper escape characters. The backslash has special meaning in Python strings. You have three choices: 1. Use a "raw" string: apps.Documents.Open(r'D:\projects\Myself\HelloPython\src\Drugreservoir.doc') 2. Double the backslashes: apps.Documents.Open('D:\\projects\\Myself\\HelloPython\\src\\Drugreservoir.doc') 3. Use forward slashes: apps.Documents.Open('D:/projects/Myself/HelloPython/src/Drugreservoir.doc') -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From cool_go_blue at yahoo.com Wed Jun 15 22:03:31 2011 From: cool_go_blue at yahoo.com (cool_go_blue) Date: Wed, 15 Jun 2011 13:03:31 -0700 (PDT) Subject: [python-win32] UnicodeEncodingError when print a doc file In-Reply-To: <4DF90767.9040802@probo.com> Message-ID: <951180.58863.qm@web43137.mail.sp1.yahoo.com> Thank you so much. It works. But where can I find the APIs such as Dispatch vs gencache.EnsureDispatch? Now, I have another problem. Using the auto save, all auto-numbers before paragraphs are not read by the following code: for word in doc.Content.Text.encode("cp1252", "replace").split(): ??? print word ??? count += 1 print "total word: " , count It works for the manual saved txt file. --- On Wed, 6/15/11, Tim Roberts wrote: From: Tim Roberts Subject: Re: [python-win32] UnicodeEncodingError when print a doc file To: "Python-Win32 List" Date: Wednesday, June 15, 2011, 3:26 PM cool_go_blue wrote: > this is the first three lines of my code: > > app = win32com.client.Dispatch('Word.Application') > app.Documents.Open('D:\projects\Myself\HelloPython\src\Drugreservoir.doc') > app.ActiveDocument.SaveAs('D:\projects\Myself\HelloPython\src\Drugreservoir1.txt',FileFormat=win32com.client.constants.wdFormatText) > If you use this instead: ? ? app = win32com.client.gencache.EnsureDispatch('Word.Application') then the framework will build a Python wrapper for objects of that type, and that Python wrapper will create the constants. You MUST get in the habit of using the proper escape characters.? The backslash has special meaning in Python strings.? You have three choices: 1. Use a "raw" string: ??? apps.Documents.Open(r'D:\projects\Myself\HelloPython\src\Drugreservoir.doc') 2. Double the backslashes: ??? apps.Documents.Open('D:\\projects\\Myself\\HelloPython\\src\\Drugreservoir.doc') 3. Use forward slashes: ??? apps.Documents.Open('D:/projects/Myself/HelloPython/src/Drugreservoir.doc') -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Wed Jun 15 22:12:21 2011 From: timr at probo.com (Tim Roberts) Date: Wed, 15 Jun 2011 13:12:21 -0700 Subject: [python-win32] UnicodeEncodingError when print a doc file In-Reply-To: <951180.58863.qm@web43137.mail.sp1.yahoo.com> References: <951180.58863.qm@web43137.mail.sp1.yahoo.com> Message-ID: <4DF91225.7060900@probo.com> cool_go_blue wrote: > Thank you so much. It works. But where can I find the APIs such as > Dispatch vs gencache.EnsureDispatch? > To a certain extent, this comes from on-the-job experience. It is described in the win32com documentation. There's also a couple of books on Python in Windows ("Python Programming on Win32" is one). > Now, I have another problem. Using the auto save, all auto-numbers > before paragraphs are not read by the following code: > > for word in doc.Content.Text.encode("cp1252", "replace").split(): > print word > count += 1 > print "total word: " , count > > It works for the manual saved txt file. > You aren't using "auto save" here. You are still reading the document directly from the application. The idea was, after you save the document as text, you go read that text file instead of using doc.Content.Text. You aren't THINKING about your problem. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From cool_go_blue at yahoo.com Wed Jun 15 22:21:42 2011 From: cool_go_blue at yahoo.com (cool_go_blue) Date: Wed, 15 Jun 2011 13:21:42 -0700 (PDT) Subject: [python-win32] UnicodeEncodingError when print a doc file In-Reply-To: <4DF91225.7060900@probo.com> Message-ID: <161844.74180.qm@web43132.mail.sp1.yahoo.com> So, my following code: app = win32com.client.gencache.EnsureDispatch('Word.Application') app.Documents.Open(r'D:/projects/Myself/HelloPython/src/Drugreservoir.doc') app.ActiveDocument.SaveAs(r'D:/projects/Myself/HelloPython/src/Drugreservoir1.txt',FileFormat=win32com.client.constants.wdFormatText) doc = app.Documents.Open(r'D:/projects/Myself/HelloPython/src/Drugreservoir1.txt') count = 0 for word in doc.Content.Text.encode("cp1252", "replace").split(): ??? print word Does SaveAs save the doc to a txt file? What I was thinking is "app.Documents.Open('D:/projects/Myself/HelloPython/src/Drugreservoir1.txt')" can open the txt file which I can read. Is there any way I can read the saved txt file after SaveAs... --- On Wed, 6/15/11, Tim Roberts wrote: From: Tim Roberts Subject: Re: [python-win32] UnicodeEncodingError when print a doc file To: "Python-Win32 List" Date: Wednesday, June 15, 2011, 4:12 PM cool_go_blue wrote: > Thank you so much. It works. But where can I find the APIs such as > Dispatch vs gencache.EnsureDispatch? > To a certain extent, this comes from on-the-job experience.? It is described in the win32com documentation.? There's also a couple of books on Python in Windows ("Python Programming on Win32" is one). > Now, I have another problem. Using the auto save, all auto-numbers > before paragraphs are not read by the following code: > > for word in doc.Content.Text.encode("cp1252", "replace").split(): >? ???print word >? ???count += 1 > print "total word: " , count > > It works for the manual saved txt file. > You aren't using "auto save" here.? You are still reading the document directly from the application.? The idea was, after you save the document as text, you go read that text file instead of using doc.Content.Text.? You aren't THINKING about your problem. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Thu Jun 16 01:52:30 2011 From: timr at probo.com (Tim Roberts) Date: Wed, 15 Jun 2011 16:52:30 -0700 Subject: [python-win32] UnicodeEncodingError when print a doc file In-Reply-To: <161844.74180.qm@web43132.mail.sp1.yahoo.com> References: <161844.74180.qm@web43132.mail.sp1.yahoo.com> Message-ID: <4DF945BE.3060509@probo.com> cool_go_blue wrote: > So, my following code: > > app = win32com.client.gencache.EnsureDispatch('Word.Application') > app.Documents.Open(r'D:/projects/Myself/HelloPython/src/Drugreservoir.doc') > app.ActiveDocument.SaveAs(r'D:/projects/Myself/HelloPython/src/Drugreservoir1.txt',FileFormat=win32com.client.constants.wdFormatText) > doc = > app.Documents.Open(r'D:/projects/Myself/HelloPython/src/Drugreservoir1.txt') > count = 0 > for word in doc.Content.Text.encode("cp1252", "replace").split(): > print word > > Does SaveAs save the doc to a txt file? What I was thinking is > "app.Documents.Open('D:/projects/Myself/HelloPython/src/Drugreservoir1.txt')" > can open the txt file which I can read. Is there any way I can read > the saved txt file after SaveAs... > Well, of course there is. At that point, you have a plain, old, ordinary text file. Just use the normal Python techniques to read it. doc = open(r'D:/projects/Myself/HelloPython/src/Drugreservoir1.txt') for word in doc.read().split(): print word -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From cool_go_blue at yahoo.com Thu Jun 16 03:03:14 2011 From: cool_go_blue at yahoo.com (cool_go_blue) Date: Wed, 15 Jun 2011 18:03:14 -0700 (PDT) Subject: [python-win32] UnicodeEncodingError when print a doc file In-Reply-To: <4DF945BE.3060509@probo.com> Message-ID: <115167.10803.qm@web43132.mail.sp1.yahoo.com> THanks. After replying to your email, I thought about what you wrote, just like what you said in the following email. So, for a normal text file, just use open to read the file. There is no need to use the way to open a word document via win32com to read a text file. Will win32com consume more time and memory to read a text file than the general input stream? Thanks again. --- On Wed, 6/15/11, Tim Roberts wrote: From: Tim Roberts Subject: Re: [python-win32] UnicodeEncodingError when print a doc file To: "Python-Win32 List" Date: Wednesday, June 15, 2011, 7:52 PM cool_go_blue wrote: > So, my following code: > > app = win32com.client.gencache.EnsureDispatch('Word.Application') > app.Documents.Open(r'D:/projects/Myself/HelloPython/src/Drugreservoir.doc') > app.ActiveDocument.SaveAs(r'D:/projects/Myself/HelloPython/src/Drugreservoir1.txt',FileFormat=win32com.client.constants.wdFormatText) > doc = > app.Documents.Open(r'D:/projects/Myself/HelloPython/src/Drugreservoir1.txt') > count = 0 > for word in doc.Content.Text.encode("cp1252", "replace").split(): >? ???print word > > Does SaveAs save the doc to a txt file? What I was thinking is > "app.Documents.Open('D:/projects/Myself/HelloPython/src/Drugreservoir1.txt')" > can open the txt file which I can read. Is there any way I can read > the saved txt file after SaveAs... > Well, of course there is.? At that point, you have a plain, old, ordinary text file.? Just use the normal Python techniques to read it. ? ? doc = open(r'D:/projects/Myself/HelloPython/src/Drugreservoir1.txt') ? ? for word in doc.read().split(): ? ? ? ? print word -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Thu Jun 16 03:05:18 2011 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 16 Jun 2011 13:05:18 +1200 Subject: [python-win32] Creating PyCComboBox? In-Reply-To: <4DF88B07.4040108@gmail.com> References: <4DF31170.6040600@canterbury.ac.nz> <4DF88B07.4040108@gmail.com> Message-ID: <4DF956CE.6010904@canterbury.ac.nz> Mark Hammond wrote: > I think you just want a CreateWindow(Ex) with "Combobox" as the class. Yes, but the puzzle was how to get a PyCComboBox object rather than a raw window handle. I discovered it can be done by calling CreateWindowFromHandle on the resulting handle, but I don't think I should have to do that. All the other PyCFoo classes have a corresponding CreateFoo function, but CreateComboBox seems to be missing. -- Greg From timr at probo.com Thu Jun 16 03:25:50 2011 From: timr at probo.com (Tim Roberts) Date: Wed, 15 Jun 2011 18:25:50 -0700 Subject: [python-win32] UnicodeEncodingError when print a doc file In-Reply-To: <115167.10803.qm@web43132.mail.sp1.yahoo.com> References: <115167.10803.qm@web43132.mail.sp1.yahoo.com> Message-ID: <4DF95B9E.5090807@probo.com> cool_go_blue wrote: > THanks. After replying to your email, I thought about what you wrote, > just like what you said in the following email. So, for a normal text > file, just use open to read the file. There is no need to use the way > to open a word document via win32com to read a text file. Will > win32com consume more time and memory to read a text file than the > general input stream? > It's not win32com that is the issue. Win32com is merely the gateway you are using to run Microsoft Word. And yes, Microsoft Word consumes a HELL of a lot more time and memory than reading a file using Python I/O. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From Tom.Hawkins at innospecinc.com Thu Jun 16 09:15:07 2011 From: Tom.Hawkins at innospecinc.com (Tom Hawkins) Date: Thu, 16 Jun 2011 08:15:07 +0100 Subject: [python-win32] UnicodeEncodingError when print a doc file Message-ID: <80EF6E679A466046BA07D071932847B32325BB@UKEPX101.innospec.itnet.octel> >Does SaveAs save the doc to a txt file? What I was thinking is >"app.Documents.Open('D:/projects/Myself/HelloPython/src/Drugreservoir1. txt')" can >open the txt file which I can read. Is there any way I can read the saved txt file after >SaveAs... Yes of course, you can use the ordinary Python file functions as described here: http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-fil es For example: myfile = open(r'D:\projects\Myself\HelloPython\src\Drugreservoir.txt') filetext = myfile.read() myfile.close() will read the entire contents of the text file into the Python variable filetext. If you just want to get the word count of this text, you don't need to use a loop, by the way - you can get it from: wordcount = len(filetext.split()) Tom Hawkins Principal Scientist Innospec Inc Tel: +44 (0)151 356 6197 Fax: +44 (0)151 356 6112 From shashwat.ds at gmail.com Fri Jun 17 00:16:37 2011 From: shashwat.ds at gmail.com (Shashwat Sinha) Date: Thu, 16 Jun 2011 15:16:37 -0700 Subject: [python-win32] Python vs Outlook Question Message-ID: Hi, I wrote this simple code that works fine: import win32com.client as W olook = W.gencache.EnsureDispatch("%s.Application" %profilename) mail = olook.CreateItem(W.constants.olMailItem) mail.Recipients.Add('xx at yahoo.com) mail.Subject = 'Hello' mail.Body = 'Hello' mail.Send() When I have Outlook open it sends the email from my Outlook account. How can I change the "From" field in the code so that I can specify a different sender? Also how can I add attachment from this python code? Thanks, Sinha. -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Fri Jun 17 01:21:06 2011 From: timr at probo.com (Tim Roberts) Date: Thu, 16 Jun 2011 16:21:06 -0700 Subject: [python-win32] Python vs Outlook Question In-Reply-To: References: Message-ID: <4DFA8FE2.2070000@probo.com> Shashwat Sinha wrote: > Hi, > > I wrote this simple code that works fine: > > import win32com.client as W > > olook = W.gencache.EnsureDispatch("%s.Application" %profilename) > mail = olook.CreateItem(W.constants.olMailItem) > mail.Recipients.Add('xx at yahoo.com ) > mail.Subject = 'Hello' > mail.Body = 'Hello' > mail.Send() > > When I have Outlook open it sends the email from my Outlook account. > How can I change the "From" field in the code so that I can specify a > different sender? Also how can I add attachment from this python code? Search for the Outlook object model. Your "mail" object is a MailItem object. That object has many properties, including SenderEmailAddress, SenderEmailType, and SenderName. It also has an Attachments property, which is a collection. You should be able to do something like this: mail.Attachments.Add( filename, win32com.constants.olByValue ) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From shashwat.ds at gmail.com Fri Jun 17 01:57:39 2011 From: shashwat.ds at gmail.com (Shashwat Sinha) Date: Thu, 16 Jun 2011 16:57:39 -0700 Subject: [python-win32] Python vs Outlook Question In-Reply-To: <4DFA8FE2.2070000@probo.com> References: <4DFA8FE2.2070000@probo.com> Message-ID: Hello Tim, Thanks for your response. After sending the post I was able to do attachments but other properties like SenderEmailAddress are not working. It gives me an AttributeError as follows: Traceback (most recent call last): File "autoMailer.py", line 146, in AutoMailSend() File "autoMailer.py", line 27, in __init__ self.sendMail("Outlook") File "autoMailer.py", line 118, in sendMail mail.SenderEmailAddress = 'shashwat.ds at gmail.com' File "C:\Python272\lib\site-packages\win32com\client\__init__.py", line 470, i n __setattr__ raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr )) *AttributeError: '' object has no attribute 'SenderEmailAddress'* C:\Temp> I am confused as 'Attachments' works but not other properties. Could you provide some more hints? I was also trying to add signature by doing: mail.AddBusinessCard = 'Signature1' but that too gave an error. Thanks for your help. Sinha. On Thu, Jun 16, 2011 at 4:21 PM, Tim Roberts wrote: > Shashwat Sinha wrote: > > Hi, > > > > I wrote this simple code that works fine: > > > > import win32com.client as W > > > > olook = W.gencache.EnsureDispatch("%s.Application" %profilename) > > mail = olook.CreateItem(W.constants.olMailItem) > > mail.Recipients.Add('xx at yahoo.com ) > > mail.Subject = 'Hello' > > mail.Body = 'Hello' > > mail.Send() > > > > When I have Outlook open it sends the email from my Outlook account. > > How can I change the "From" field in the code so that I can specify a > > different sender? Also how can I add attachment from this python code? > > Search for the Outlook object model. Your "mail" object is a MailItem > object. That object has many properties, including SenderEmailAddress, > SenderEmailType, and SenderName. > > It also has an Attachments property, which is a collection. You should > be able to do something like this: > > mail.Attachments.Add( filename, win32com.constants.olByValue ) > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Fri Jun 17 02:33:40 2011 From: timr at probo.com (Tim Roberts) Date: Thu, 16 Jun 2011 17:33:40 -0700 Subject: [python-win32] Python vs Outlook Question In-Reply-To: References: <4DFA8FE2.2070000@probo.com> Message-ID: <4DFAA0E4.3080305@probo.com> Shashwat Sinha wrote: > > Thanks for your response. After sending the post I was able to do > attachments but other properties like SenderEmailAddress are not > working. It gives me an AttributeError as follows: > > Traceback (most recent call last): > ... > File "autoMailer.py", line 118, in sendMail > mail.SenderEmailAddress = 'shashwat.ds at gmail.com' > > File "C:\Python272\lib\site-packages\win32com\client\__init__.py", > line 470, i > n __setattr__ > raise AttributeError("'%s' object has no attribute '%s'" % > (repr(self), attr > )) > *AttributeError: ' Library._MailIte > m instance at 0x39818584>' object has no attribute 'SenderEmailAddress'* > C:\Temp> Yes, I see now that the documentation says that's a "read-only" attribute; it is only present when you read an existing message that's already in your Outlook data store. Apparently, Outlook will only send messages that come from one of your Outlook identities. That's not really much of a surprise. > I am confused as 'Attachments' works but not other properties. Could > you provide some more hints? I was also trying to add signature by > doing: > > mail.AddBusinessCard = 'Signature1' AddBusinessCard is a method, not a property. It has to be called like a function. However, it doesn't accept a simple string; it takes a ContactItem object, which you would have to get from the list of Outlook contacts. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From shashwat.ds at gmail.com Fri Jun 17 03:29:08 2011 From: shashwat.ds at gmail.com (Shashwat Sinha) Date: Thu, 16 Jun 2011 18:29:08 -0700 Subject: [python-win32] Python vs Outlook Question In-Reply-To: <4DFAA0E4.3080305@probo.com> References: <4DFA8FE2.2070000@probo.com> <4DFAA0E4.3080305@probo.com> Message-ID: Thanks Tim. On Thu, Jun 16, 2011 at 5:33 PM, Tim Roberts wrote: > Shashwat Sinha wrote: > > > > Thanks for your response. After sending the post I was able to do > > attachments but other properties like SenderEmailAddress are not > > working. It gives me an AttributeError as follows: > > > > Traceback (most recent call last): > > ... > > File "autoMailer.py", line 118, in sendMail > > mail.SenderEmailAddress = 'shashwat.ds at gmail.com' > > > > File "C:\Python272\lib\site-packages\win32com\client\__init__.py", > > line 470, i > > n __setattr__ > > raise AttributeError("'%s' object has no attribute '%s'" % > > (repr(self), attr > > )) > > *AttributeError: ' > Library._MailIte > > m instance at 0x39818584>' object has no attribute 'SenderEmailAddress'* > > C:\Temp> > > Yes, I see now that the documentation says that's a "read-only" > attribute; it is only present when you read an existing message that's > already in your Outlook data store. Apparently, Outlook will only send > messages that come from one of your Outlook identities. > > That's not really much of a surprise. > > > I am confused as 'Attachments' works but not other properties. Could > > you provide some more hints? I was also trying to add signature by > > doing: > > > > mail.AddBusinessCard = 'Signature1' > > AddBusinessCard is a method, not a property. It has to be called like a > function. However, it doesn't accept a simple string; it takes a > ContactItem object, which you would have to get from the list of Outlook > contacts. > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Fri Jun 17 05:18:28 2011 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 17 Jun 2011 15:18:28 +1200 Subject: [python-win32] ANN: PyGUI 2.5 Message-ID: <4DFAC784.1010609@canterbury.ac.nz> PyGUI 2.5 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ Lots of new stuff in this version. Highlights include: - Improved facilities for customising the standard menus. - Functions for creating PyGUI Images from PIL images and numpy arrays. - ListButton - a pop-up or pull-down menu of choices. - GridView - a user-defined view consisting of a regular grid of cells. - PaletteView - a GridView specialised for implementing tool palettes. There is also a big pile of other improvements and bug fixes. See the CHANGES file for full details. What is PyGUI? -------------- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. -- Gregory Ewing greg.ewing at canterbury.ac.nz http://www.cosc.canterbury.ac.nz/greg.ewing/ From reckoner at gmail.com Fri Jun 17 15:19:44 2011 From: reckoner at gmail.com (reckoner) Date: Fri, 17 Jun 2011 06:19:44 -0700 Subject: [python-win32] Access Most Recently Used (MRU) entries ? Message-ID: <4DFB5470.10305@gmail.com> Is it possible to get access to the Most Recently Used (MRU) list in windows. This is where Windows keeps a list of the most recently opened documents and programs. By the way, I'm on Windows XP. Thanks! From mail at timgolden.me.uk Fri Jun 17 15:54:26 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 17 Jun 2011 14:54:26 +0100 Subject: [python-win32] Access Most Recently Used (MRU) entries ? In-Reply-To: <4DFB5470.10305@gmail.com> References: <4DFB5470.10305@gmail.com> Message-ID: <4DFB5C92.2040100@timgolden.me.uk> On 17/06/2011 14:19, reckoner wrote: > Is it possible to get access to the Most Recently Used (MRU) list in > windows. This is where Windows keeps a list of the most recently opened > documents and programs. > > By the way, I'm on Windows XP. Depends what you need to do. To add in item, use the SHAddToRecentDocs API from the shell module: import sys from win32com.shell import shell, shellcon shell.SHAddToRecentDocs ( shellcon.SHARD_PATHW, sys.executable ) To access its contents (in file system terms): import os, sys from win32com.shell import shell, shellcon mru = shell.SHGetSpecialFolderPath (0, shellcon.CSIDL_RECENT, 0) print os.listdir (mru) To access it as shell folder: import os, sys from win32com.shell import shell, shellcon mru_pidl = shell.SHGetSpecialFolderLocation (0, shellcon.CSIDL_RECENT) desktop = shell.SHGetDesktopFolder () mru_folder = desktop.BindToObject ( mru_pidl, None, shell.IID_IShellFolder ) for i in mru_folder: print mru_folder.GetDisplayNameOf (i, shellcon.SHGDN_NORMAL) TJG From greg.ewing at canterbury.ac.nz Sat Jun 18 06:31:28 2011 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 18 Jun 2011 16:31:28 +1200 Subject: [python-win32] [Pygui] Installing PyGUI-2.5 on Mac OSX 10.5.8 fails In-Reply-To: <9DF6A6F7-948E-4DB9-A585-F0EE01E60598@gmail.com> References: <9DF6A6F7-948E-4DB9-A585-F0EE01E60598@gmail.com> Message-ID: <4DFC2A20.6080806@canterbury.ac.nz> Colin Brown wrote: > Macintosh:PyGUI-2.5 colin$ python setup.py install > Traceback (most recent call last): > File "setup.py", line 12, in > from distutils_extensions import pygui_build_py > ImportError: No module named distutils_extensions Sorry about that! The missing file is attached, and I'll upload a fixed distribution soon. -- Greg -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: distutils_extensions.py URL: From greg.ewing at canterbury.ac.nz Sat Jun 18 08:14:30 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 18 Jun 2011 18:14:30 +1200 Subject: [python-win32] ANN: PyGUI 2.5.1 Message-ID: <4DFC4246.2060502@canterbury.ac.nz> PyGUI 2.5.1 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ Minor update to fix missing distutils_extensions.py file. What is PyGUI? -------------- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. -- Gregory Ewing greg.ewing at canterbury.ac.nz http://www.cosc.canterbury.ac.nz/greg.ewing/ This email may be confidential and subject to legal privilege, it may not reflect the views of the University of Canterbury, and it is not guaranteed to be virus free. If you are not an intended recipient, please notify the sender immediately and erase all copies of the message and any attachments. Please refer to http://www.canterbury.ac.nz/emaildisclaimer for more information. From reckoner at gmail.com Sun Jun 19 01:00:42 2011 From: reckoner at gmail.com (reckoner) Date: Sat, 18 Jun 2011 16:00:42 -0700 Subject: [python-win32] Access Most Recently Used (MRU) entries ? In-Reply-To: References: Message-ID: <4DFD2E1A.4020404@gmail.com> > On 17/06/2011 14:19, reckoner wrote: > > Depends what you need to do. To add in item, use the SHAddToRecentDocs > API from the shell module: > > > import sys > from win32com.shell import shell, shellcon > > shell.SHAddToRecentDocs ( > shellcon.SHARD_PATHW, > sys.executable > ) > > > > To access its contents (in file system terms): > > > import os, sys > from win32com.shell import shell, shellcon > > mru = shell.SHGetSpecialFolderPath (0, shellcon.CSIDL_RECENT, 0) > print os.listdir (mru) > > > > To access it as shell folder: > > > import os, sys > from win32com.shell import shell, shellcon > > mru_pidl = shell.SHGetSpecialFolderLocation (0, shellcon.CSIDL_RECENT) > desktop = shell.SHGetDesktopFolder () > mru_folder = desktop.BindToObject ( > mru_pidl, > None, > shell.IID_IShellFolder > ) > > for i in mru_folder: > print mru_folder.GetDisplayNameOf (i, shellcon.SHGDN_NORMAL) > > > > TJG Thank you! This is a big help. Is there a way to find out which program called which item in the MRU list and when that occurred? From mail at timgolden.me.uk Sun Jun 19 23:19:21 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 19 Jun 2011 22:19:21 +0100 Subject: [python-win32] Access Most Recently Used (MRU) entries ? In-Reply-To: <4DFD2E1A.4020404@gmail.com> References: <4DFD2E1A.4020404@gmail.com> Message-ID: <4DFE67D9.9000605@timgolden.me.uk> On 19/06/2011 00:00, reckoner wrote: > >> On 17/06/2011 14:19, reckoner wrote: >> >> Depends what you need to do. To add in item, use the SHAddToRecentDocs >> API from the shell module: >> >> >> import sys >> from win32com.shell import shell, shellcon >> >> shell.SHAddToRecentDocs ( >> shellcon.SHARD_PATHW, >> sys.executable >> ) >> >> >> >> To access its contents (in file system terms): >> >> >> import os, sys >> from win32com.shell import shell, shellcon >> >> mru = shell.SHGetSpecialFolderPath (0, shellcon.CSIDL_RECENT, 0) >> print os.listdir (mru) >> >> >> >> To access it as shell folder: >> >> >> import os, sys >> from win32com.shell import shell, shellcon >> >> mru_pidl = shell.SHGetSpecialFolderLocation (0, shellcon.CSIDL_RECENT) >> desktop = shell.SHGetDesktopFolder () >> mru_folder = desktop.BindToObject ( >> mru_pidl, >> None, >> shell.IID_IShellFolder >> ) >> >> for i in mru_folder: >> print mru_folder.GetDisplayNameOf (i, shellcon.SHGDN_NORMAL) >> >> >> >> TJG > > > Thank you! This is a big help. Is there a way to find out which program > called which item in the MRU list and when that occurred? Not AFAIK. However, you can assume that the program associated with the file extension created the link and that the time the link was created was when it occurred. You can find the associated program with the win32api.FindExecutable API and the standard os.getmtime will tell you when the link was created. TJG From matt.jibson at gmail.com Tue Jun 21 00:58:12 2011 From: matt.jibson at gmail.com (Matt Jibson) Date: Mon, 20 Jun 2011 16:58:12 -0600 Subject: [python-win32] windows 2008 services on reboot Message-ID: I'm using the win32 extensions to install and run a service that can take 10-15 seconds to gracefully shutdown. It successfully receives the shutdown signal, but Windows Server 2008 kills the process before it can shutdown normally. Works fine on Windows Server 2003. I'm aware this is possibly a Windows issue. Anyone seen this or have ideas? -------------- next part -------------- An HTML attachment was scrubbed... URL: From cfuller084 at thinkingplanet.net Tue Jun 21 02:59:44 2011 From: cfuller084 at thinkingplanet.net (Chris Fuller) Date: Mon, 20 Jun 2011 19:59:44 -0500 Subject: [python-win32] windows 2008 services on reboot In-Reply-To: References: Message-ID: <201106201959.47302.cfuller084@thinkingplanet.net> I believe it is possible to catch the shutdown event, cancel it, and send a new one when the service is done cleaning up. Not pretty, but nothing ever is when there's a hardwired timeout involved. On Monday 20 June 2011, Matt Jibson wrote: > I'm using the win32 extensions to install and run a service that can take > 10-15 seconds to gracefully shutdown. It successfully receives the shutdown > signal, but Windows Server 2008 kills the process before it can shutdown > normally. Works fine on Windows Server 2003. I'm aware this is possibly a > Windows issue. Anyone seen this or have ideas? From imageguy1206 at gmail.com Tue Jun 21 14:23:14 2011 From: imageguy1206 at gmail.com (geoff) Date: Tue, 21 Jun 2011 09:23:14 -0300 Subject: [python-win32] [Pygui] Convert RGBA to BGRA using standard library? In-Reply-To: <4DE0B884.10206@canterbury.ac.nz> References: <4DE0B884.10206@canterbury.ac.nz> Message-ID: On Sat, May 28, 2011 at 5:55 AM, Greg Ewing wrote: > Can anyone think of an efficient way to convert a string > full of RGBA image data to BGRA, using only what's available > in the standard library? > > I'm trying to add a function to PyGUI for creating an Image > object from arbitrary data. The problem I'm having is that > GDI+ on Windows expects BGRA, whereas most other platforms > deal with RGBA. I don't want to require the user to supply > the data in different formats on different platforms, so > PyGUI needs to be able to convert where necessary. > > I know the conversion can be done easily using something > like PIL or numpy, but I'm after a solution that doesn't > depend on any third-party libraries. > > -- > Greg > ______________________________**_________________ > Pygui mailing list > Pygui at python.org > http://mail.python.org/**mailman/listinfo/pygui > Greg, I had to solve this problem in another application and ended up using the array module and the with the slice syntax. import array input = "rgbaRGBA1234" ba = array.array('c', input) ba[0::4], ba[2::4] = ba[2::4], ba[0::4] print ba.tostring() >> bgraBGRA3214 It is fairly fast too. Good luck and keep up the great work. -------------- next part -------------- An HTML attachment was scrubbed... URL: From saunders.m3 at we-learn.com Tue Jun 21 17:13:44 2011 From: saunders.m3 at we-learn.com (M Saunders TAS) Date: Tue, 21 Jun 2011 16:13:44 +0100 Subject: [python-win32] How to get a proxy instance of a WMI object. Message-ID: <3A8573B667AAE24D810B12B0ECDEB0B1012DE1923CDD@EXVS-1.WARWICK.welearn.internal> Hi, I'm trying to use python and the fantastic WMI module to manage Hyper-V virtual machine resources and am having problems trying to modify properties of an instance to pass back via WMI. The following code in powershell is what I need to emulate in python: $vmms = gwmi -namespace root\virtualization Msvm_VirtualSystemManagementService $hardDisk = gwmi -namespace root\virtualization Msvm_ResourceAllocationSettingData -filter InstanceID='Microsoft:Definition\\353B3BE8-310C-4CF4-839E-4E1B14616136\\Default'" $hardDisk.Address = 0 $vmms.AddVirtualSystemResources($vm,@($hardDisk.GetText(1))) The equivalent python code below produces a COM error "Provider is not capable of the attempted operation" when trying to change object properties. import wmi c = wmi.WMI(namespace="virtualization", find_classes=False) VMMS = c.Msvm_VirtualSystemManagementService()[-1] HD = c.Msvm_ResourceAllocationSettingData(InstanceID='Microsoft:Definition\\353B3BE8-310C-4CF4-839E-4E1B14616136\\Default') HD.Address = 0 VMMS.AddVirtualSystemResources([HD.gettext_(1),], VM) I am sure that it is something simple and obvious that I am doing incorrectly so apologies in advance for my stupidity. Any help or suggestions will be gratefully received. Thanks Matt Warwickshire Schools Email System This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please forward to: postmaster at we-learn.com. If the content of this email is considered to be inappropriate or offensive please report by forwarding to: reportabuse at we-learn.com From mail at timgolden.me.uk Tue Jun 21 17:51:21 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 21 Jun 2011 16:51:21 +0100 Subject: [python-win32] How to get a proxy instance of a WMI object. In-Reply-To: <3A8573B667AAE24D810B12B0ECDEB0B1012DE1923CDD@EXVS-1.WARWICK.welearn.internal> References: <3A8573B667AAE24D810B12B0ECDEB0B1012DE1923CDD@EXVS-1.WARWICK.welearn.internal> Message-ID: <4E00BDF9.7040005@timgolden.me.uk> On 21/06/2011 16:13, M Saunders TAS wrote: > I'm trying to use python and the fantastic WMI module to manage > Hyper-V virtual machine resources and am having problems trying to > modify properties of an instance to pass back via WMI. > > The following code in powershell is what I need to emulate in python: [... snip horrendous Powershell stuff ...] I never can understand why people like Powershell syntax so much > The equivalent python code below produces a COM error "Provider is > not capable of the attempted operation" when trying to change object > properties. I'm not going to be much help here, I'm afraid: I don't have access to a Hyper-V installation and the error message is a fairly generic one. What might just help is a full traceback which would show exactly where the error is arising. Frankly, I'm not too hopeful, although I'm happy to try. TJG From graham.bloice at trihedral.com Tue Jun 21 18:06:37 2011 From: graham.bloice at trihedral.com (Graham Bloice) Date: Tue, 21 Jun 2011 17:06:37 +0100 Subject: [python-win32] How to get a proxy instance of a WMI object. In-Reply-To: <3A8573B667AAE24D810B12B0ECDEB0B1012DE1923CDD@EXVS-1.WARWICK.welearn.internal> References: <3A8573B667AAE24D810B12B0ECDEB0B1012DE1923CDD@EXVS-1.WARWICK.welearn.internal> Message-ID: <4E00C18D.60201@trihedral.com> On 21/06/2011 16:13, M Saunders TAS wrote: > Hi, > > I'm trying to use python and the fantastic WMI module to manage Hyper-V virtual machine resources and am having problems trying to modify properties of an instance to pass back via WMI. > > The following code in powershell is what I need to emulate in python: > > $vmms = gwmi -namespace root\virtualization Msvm_VirtualSystemManagementService > $hardDisk = gwmi -namespace root\virtualization Msvm_ResourceAllocationSettingData -filter InstanceID='Microsoft:Definition\\353B3BE8-310C-4CF4-839E-4E1B14616136\\Default'" > $hardDisk.Address = 0 > $vmms.AddVirtualSystemResources($vm,@($hardDisk.GetText(1))) > > The equivalent python code below produces a COM error "Provider is not capable of the attempted operation" when trying to change object properties. > > import wmi > c = wmi.WMI(namespace="virtualization", find_classes=False) > VMMS = c.Msvm_VirtualSystemManagementService()[-1] > HD = c.Msvm_ResourceAllocationSettingData(InstanceID='Microsoft:Definition\\353B3BE8-310C-4CF4-839E-4E1B14616136\\Default') > HD.Address = 0 > VMMS.AddVirtualSystemResources([HD.gettext_(1),], VM) > > I am sure that it is something simple and obvious that I am doing incorrectly so apologies in advance for my stupidity. > Any help or suggestions will be gratefully received. > > Thanks > > Matt > > In the Python call to AddVirtualSystemResources() you've reversed the order of the parameters. -- Regards, Graham Bloice -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Tue Jun 21 19:35:10 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 21 Jun 2011 18:35:10 +0100 Subject: [python-win32] How to get a proxy instance of a WMI object. In-Reply-To: <4E00C18D.60201@trihedral.com> References: <3A8573B667AAE24D810B12B0ECDEB0B1012DE1923CDD@EXVS-1.WARWICK.welearn.internal> <4E00C18D.60201@trihedral.com> Message-ID: <4E00D64E.3070402@timgolden.me.uk> On 21/06/2011 17:06, Graham Bloice wrote: > In the Python call to AddVirtualSystemResources() you've reversed the > order of the parameters. Aha. And to help out the OP, you can pass parameters by name as well as by position. (As you have done in the previous method call). TJG From saunders.m3 at we-learn.com Tue Jun 21 22:57:53 2011 From: saunders.m3 at we-learn.com (M Saunders TAS) Date: Tue, 21 Jun 2011 21:57:53 +0100 Subject: [python-win32] How to get a proxy instance of a WMI object. In-Reply-To: <4E00BDF9.7040005@timgolden.me.uk> References: <3A8573B667AAE24D810B12B0ECDEB0B1012DE1923CDD@EXVS-1.WARWICK.welearn.internal> <4E00BDF9.7040005@timgolden.me.uk> Message-ID: <3A8573B667AAE24D810B12B0ECDEB0B1012DE14EF673@EXVS-1.WARWICK.welearn.internal> > [... snip horrendous Powershell stuff ...] > > I never can understand why people like Powershell syntax so much Indeed, it is syntactically horrendous. I wrote that after I hit problem in Python to test the concept, honest... > I'm not going to be much help here, I'm afraid: I don't have access > to a Hyper-V installation I can give you access to one ;) > What might just help is a full traceback which would show exactly > where the error is arising. Frankly, I'm not too hopeful, although > I'm happy to try. python scsi_add_short.py Traceback (most recent call last): File "scsi_add_short.py", line 15, in HD.Address = "100" File "c:\python27\lib\site-packages\wmi.py", line 571, in __setattr__ handle_com_error () File "c:\python27\lib\site-packages\wmi.py", line 241, in handle_com_error raise klass (com_error=err) wmi.x_wmi: The traceback, for the following code; import wmi c = wmi.WMI("hostname", namespace="virtualization", find_classes=False) VM = c.Msvm_ComputerSystem(ElementName="vmname")[-1] DiskPool = c.Msvm_ResourcePool(ResourceType=22,ResourceSubtype="Microsoft Physical Disk Drive")[-1] Disks = DiskPool.associators(wmi_result_class="Msvm_DiskDrive") Disk = [d for d in Disks if d.DriveNumber==10][0] VSSDs = VM.associators(wmi_result_class="Msvm_VirtualSystemSettingData") VSSD = [v for v in VSSDs if v.SettingType==3][0] SCSIs = VSSD.associators(wmi_result_class="Msvm_ResourceAllocationSettingData") SCSI = [s for s in SCSIs if s.ResourceType==6][0] AC = c.Msvm_AllocationCapabilities(ResourceType=22,ResourceSubtype="Microsoft Physical Disk Drive")[-1] Default = c.Msvm_SettingsDefineCapabilities(ValueRange=0,GroupComponent=AC.Path_.Path)[-1] # Problematic section HD = Default.PartComponent HD.Address = "100" HD.Parent = SCSI.Path_.Path HD.HostResource= DISK.Path_.Path VMMS.AddVirtualSystemResources(VM, [HD.gettext_(1),]) > In the Python call to AddVirtualSystemResources() you've reversed the order of the parameters. I'm sure in testing there was a reason why i'd switched them around, but I cannot remember right now. As you can see in this example they are the correct way around (but the code doesn't get that far anyway). Thanks again for looking. Matt Warwickshire Schools Email System This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please forward to: postmaster at we-learn.com. If the content of this email is considered to be inappropriate or offensive please report by forwarding to: reportabuse at we-learn.com From greg.ewing at canterbury.ac.nz Wed Jun 22 01:18:20 2011 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 22 Jun 2011 11:18:20 +1200 Subject: [python-win32] [Pygui] Convert RGBA to BGRA using standard library? In-Reply-To: References: <4DE0B884.10206@canterbury.ac.nz> Message-ID: <4E0126BC.806@canterbury.ac.nz> geoff wrote: > Greg, I had to solve this problem in another application and ended up > using the array module and the with the slice syntax. > > import array > > input = "rgbaRGBA1234" > ba = array.array('c', input) > ba[0::4], ba[2::4] = ba[2::4], ba[0::4] Yep, I was thinking the same thing myself. I'll give it a try next time I'm working on the problem. Thanks, Greg From greg.ewing at canterbury.ac.nz Wed Jun 22 01:53:26 2011 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 22 Jun 2011 11:53:26 +1200 Subject: [python-win32] PyGUI Example and a New Game Message-ID: <4E012EF6.9030003@canterbury.ac.nz> If anyone would like to see a substantial application built with PyGUI, you might like to take a look at my latest game, currently posted on the Pyggy Awards site: http://pyggy.pyweek.org/e/SimChip/ Any feedback you care to provide on the game would be welcome as well. :-) -- Greg From mail at timgolden.me.uk Wed Jun 22 15:19:02 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 22 Jun 2011 14:19:02 +0100 Subject: [python-win32] How to get a proxy instance of a WMI object. In-Reply-To: <3A8573B667AAE24D810B12B0ECDEB0B1012DE14EF673@EXVS-1.WARWICK.welearn.internal> References: <3A8573B667AAE24D810B12B0ECDEB0B1012DE1923CDD@EXVS-1.WARWICK.welearn.internal> <4E00BDF9.7040005@timgolden.me.uk> <3A8573B667AAE24D810B12B0ECDEB0B1012DE14EF673@EXVS-1.WARWICK.welearn.internal> Message-ID: <4E01EBC6.4050304@timgolden.me.uk> On 21/06/2011 21:57, M Saunders TAS wrote: > python scsi_add_short.py > Traceback (most recent call last): > File "scsi_add_short.py", line 15, in > HD.Address = "100" > File "c:\python27\lib\site-packages\wmi.py", line 571, in __setattr__ > handle_com_error () > File "c:\python27\lib\site-packages\wmi.py", line 241, in handle_com_error > raise klass (com_error=err) > wmi.x_wmi: u'SWbemObjectEx', u'Provider is not capable of the attempted operation ', None, > 0, -2147217372), None)> Thanks for posting. Nothing's jumping out at me I'm afraid. If you were serious about giving me access to Hyper-V I'm happy to try to poke at it at a distance if you wanted to contact me off-list. TJG From greg.ewing at canterbury.ac.nz Thu Jun 23 09:03:04 2011 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 23 Jun 2011 19:03:04 +1200 Subject: [python-win32] Finding out whether there are any visible windows Message-ID: <4E02E528.8030802@canterbury.ac.nz> In PyGUI I have a need to find out whether the application has any visible windows, so I can quit when the last visible window is closed. However, I can't seem to find a way of iterating over all the windows belonging to the application, without also getting windows belonging to *other* applications. Any suggestions? -- Greg From mail at timgolden.me.uk Thu Jun 23 09:46:15 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 23 Jun 2011 08:46:15 +0100 Subject: [python-win32] Finding out whether there are any visible windows In-Reply-To: <4E02E528.8030802@canterbury.ac.nz> References: <4E02E528.8030802@canterbury.ac.nz> Message-ID: <4E02EF47.5030003@timgolden.me.uk> On 23/06/2011 08:03, Greg Ewing wrote: > In PyGUI I have a need to find out whether the application > has any visible windows, so I can quit when the last visible > window is closed. > > However, I can't seem to find a way of iterating over all > the windows belonging to the application, without also > getting windows belonging to *other* applications. I think you're stuck with that (although I haven't trawled post-XP additions to the API to see if anything's changed). Just for information, my nearly-what-you-want is here: http://timgolden.me.uk/python/win32_how_do_i/find-the-window-for-my-subprocess.html but I imagine you're already there if you're asking this question :) TJG From greg.ewing at canterbury.ac.nz Thu Jun 23 10:00:13 2011 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 23 Jun 2011 20:00:13 +1200 Subject: [python-win32] Finding out whether there are any visible windows In-Reply-To: <4E02EF47.5030003@timgolden.me.uk> References: <4E02E528.8030802@canterbury.ac.nz> <4E02EF47.5030003@timgolden.me.uk> Message-ID: <4E02F28D.6050701@canterbury.ac.nz> Tim Golden wrote: > Just for information, my nearly-what-you-want is here: > > http://timgolden.me.uk/python/win32_how_do_i/find-the-window-for-my-subprocess.html Yep, I came up something similar -- was just wondering whether there was some more obvious way that I was missing. Seems not. Thanks, Greg From skippy.hammond at gmail.com Thu Jun 23 13:16:44 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 23 Jun 2011 21:16:44 +1000 Subject: [python-win32] windows 2008 services on reboot In-Reply-To: References: Message-ID: <4E03209C.2050109@gmail.com> On 21/06/2011 8:58 AM, Matt Jibson wrote: > I'm using the win32 extensions to install and run a service that can > take 10-15 seconds to gracefully shutdown. It successfully receives the > shutdown signal, but Windows Server 2008 kills the process before it can > shutdown normally. Works fine on Windows Server 2003. I'm aware this is > possibly a Windows issue. Anyone seen this or have ideas? This is documented at http://msdn.microsoft.com/en-us/library/ms685149%28v=vs.85%29.aspx Cheers, Mark From saunders.m3 at we-learn.com Fri Jun 24 15:59:54 2011 From: saunders.m3 at we-learn.com (M Saunders TAS) Date: Fri, 24 Jun 2011 14:59:54 +0100 Subject: [python-win32] How to get a proxy instance of a WMI object. In-Reply-To: <4E01EBC6.4050304@timgolden.me.uk> References: <3A8573B667AAE24D810B12B0ECDEB0B1012DE1923CDD@EXVS-1.WARWICK.welearn.internal> <4E00BDF9.7040005@timgolden.me.uk> <3A8573B667AAE24D810B12B0ECDEB0B1012DE14EF673@EXVS-1.WARWICK.welearn.internal> <4E01EBC6.4050304@timgolden.me.uk> Message-ID: <3A8573B667AAE24D810B12B0ECDEB0B1012E08C96E21@EXVS-1.WARWICK.welearn.internal> Tim Golden wrote: > Thanks for posting. Nothing's jumping out at me I'm afraid. I've had another chance to look at this today and have found a workaround using win32com.client but still cannot figure why it exempts when using the WMI module. Using WMI module HD = c.Msvm_ResourceAllocationSettingData(InstanceID='Microsoft:Definition\\353B3BE8-310C-4CF4-839E-4E1B14616136\\Default')[0] HD.Address = 30 Results in the error; wmi.x_wmi: Using win32com.client and rewrapping it using wmi._wmi_object() after setting properties works correctly. HDobj = win32com.client.Dispatch("WbemScripting.SWbemLocator")\ .ConnectServer("avs-cnode-06","root/virtualization")\ .Get("Msvm_ResourceAllocationSettingData.InstanceID='Microsoft:Definition\\353B3BE8-310C-4CF4-839E-4E1B14616136\\Default'") HDobj.Address = 30 HD = wmi._wmi_object(HDobj) Any ideas? The win32com.client is a really ugly hack. Graham Bloice wrote: > In the Python call to AddVirtualSystemResources() you've reversed the order of the parameters. Additionally the method signature for AddVirtualSystemResources() returns (Job, NewResources[], ReturnValue)> Which is backwards to the previously demonstrated powershell example. Thanks Matt Warwickshire Schools Email System This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please forward to: postmaster at we-learn.com. If the content of this email is considered to be inappropriate or offensive please report by forwarding to: reportabuse at we-learn.com From graham.bloice at trihedral.com Fri Jun 24 16:09:10 2011 From: graham.bloice at trihedral.com (Graham Bloice) Date: Fri, 24 Jun 2011 15:09:10 +0100 Subject: [python-win32] How to get a proxy instance of a WMI object. In-Reply-To: <3A8573B667AAE24D810B12B0ECDEB0B1012E08C96E21@EXVS-1.WARWICK.welearn.internal> References: <3A8573B667AAE24D810B12B0ECDEB0B1012DE1923CDD@EXVS-1.WARWICK.welearn.internal> <4E00BDF9.7040005@timgolden.me.uk> <3A8573B667AAE24D810B12B0ECDEB0B1012DE14EF673@EXVS-1.WARWICK.welearn.internal> <4E01EBC6.4050304@timgolden.me.uk> <3A8573B667AAE24D810B12B0ECDEB0B1012E08C96E21@EXVS-1.WARWICK.welearn.internal> Message-ID: <4E049A86.1010107@trihedral.com> On 24/06/2011 14:59, M Saunders TAS wrote: > > Graham Bloice wrote: >> In the Python call to AddVirtualSystemResources() you've reversed the order of the parameters. > Additionally the method signature for AddVirtualSystemResources() returns > (Job, NewResources[], ReturnValue)> > Which is backwards to the previously demonstrated powershell example. > > Thanks > > That's really handy, not! -- Regards, Graham Bloice -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Fri Jun 24 16:29:32 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 24 Jun 2011 15:29:32 +0100 Subject: [python-win32] How to get a proxy instance of a WMI object. In-Reply-To: <4E049A86.1010107@trihedral.com> References: <3A8573B667AAE24D810B12B0ECDEB0B1012DE1923CDD@EXVS-1.WARWICK.welearn.internal> <4E00BDF9.7040005@timgolden.me.uk> <3A8573B667AAE24D810B12B0ECDEB0B1012DE14EF673@EXVS-1.WARWICK.welearn.internal> <4E01EBC6.4050304@timgolden.me.uk> <3A8573B667AAE24D810B12B0ECDEB0B1012E08C96E21@EXVS-1.WARWICK.welearn.internal> <4E049A86.1010107@trihedral.com> Message-ID: <4E049F4C.5050302@timgolden.me.uk> On 24/06/2011 15:09, Graham Bloice wrote: > On 24/06/2011 14:59, M Saunders TAS wrote: >> >> Graham Bloice wrote: >>> In the Python call to AddVirtualSystemResources() you've reversed the order of the parameters. >> Additionally the method signature for AddVirtualSystemResources() returns >> (Job, NewResources[], ReturnValue)> >> Which is backwards to the previously demonstrated powershell example. >> >> Thanks >> >> > That's really handy, not! FWIW, the wmi method signature is simply a summary of whatever the .InParameters & .OutParameters give for that method. Not sure what PowerShell's doing differently here. The __setattr__ logic does involve a certain level of cacheing and redirection, so there definitely is scope for an error in the WMI code, especially as WMI is most often a read-only or a method-set technology. (ie the __setattr__ logic probably hasn't been exercised as much as it might have). I've contacted the OP off-list to see if we can take it further with a direct connection. TJG From mail at timgolden.me.uk Fri Jun 24 16:50:38 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 24 Jun 2011 15:50:38 +0100 Subject: [python-win32] How to get a proxy instance of a WMI object. In-Reply-To: <4E049F4C.5050302@timgolden.me.uk> References: <3A8573B667AAE24D810B12B0ECDEB0B1012DE1923CDD@EXVS-1.WARWICK.welearn.internal> <4E00BDF9.7040005@timgolden.me.uk> <3A8573B667AAE24D810B12B0ECDEB0B1012DE14EF673@EXVS-1.WARWICK.welearn.internal> <4E01EBC6.4050304@timgolden.me.uk> <3A8573B667AAE24D810B12B0ECDEB0B1012E08C96E21@EXVS-1.WARWICK.welearn.internal> <4E049A86.1010107@trihedral.com> <4E049F4C.5050302@timgolden.me.uk> Message-ID: <4E04A43E.50803@timgolden.me.uk> On 24/06/2011 15:29, Tim Golden wrote: > The __setattr__ logic does involve a certain level of cacheing > and redirection, so there definitely is scope for an error in > the WMI code ... and here I mean "in the code of the wmi.py module" ;) TJG From mail at timgolden.me.uk Sat Jun 25 14:05:07 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 25 Jun 2011 13:05:07 +0100 Subject: [python-win32] How to get a proxy instance of a WMI object. In-Reply-To: <3A8573B667AAE24D810B12B0ECDEB0B1012E08C96E21@EXVS-1.WARWICK.welearn.internal> References: <3A8573B667AAE24D810B12B0ECDEB0B1012DE1923CDD@EXVS-1.WARWICK.welearn.internal> <4E00BDF9.7040005@timgolden.me.uk> <3A8573B667AAE24D810B12B0ECDEB0B1012DE14EF673@EXVS-1.WARWICK.welearn.internal> <4E01EBC6.4050304@timgolden.me.uk> <3A8573B667AAE24D810B12B0ECDEB0B1012E08C96E21@EXVS-1.WARWICK.welearn.internal> Message-ID: <4E05CEF3.9050007@timgolden.me.uk> OK: a summary for those who're following the story. I was able to VPN into the OP's setup to get hold of the objects as they come along, so to speak. (Which helped tremendously in trying to see what was going on). The situation is this: When you're setting the attribute of a WMI object (via COM) you employ the usual Python __setattr__ magic, courtesy of the pywin32 COM wrappers, and then you usually call the .Put_ method of the object in question to ensure that changes are written back to the real object for which WMI is proxying. This is what the wmi module's __setattr__ logic does, modulo a certain amount of cacheing of the property object itself which is irrelevant here. Occasionally you create WMI objects from scratch, via the underlying .SpawnInstance_ method which is wrapped in the wmi module by the .new method of the _wmi_class. When this happens, you don't want to call the .Put_ method because there isn't usually an underlying object to write back to: this is a structure, such as ProcessStartup or a security structure, which will be passed into, eg, the .Create method of a Win32_Process object. Therefore, the __setattr__ logic checks that the object whose attributes are being updated has a non-empty .Path_ attribute, which would indicate that it is proxying a real, underlying object. If .Path_ is empty, .Put_ is not called. So far, so good. In the OP's case, one of the complex of objects which arise as you're trying to set up a VM was a sort of template of defaults which somehow has a real, underlying object (and therefore a non-empty Path_) but whose underlying object cannot be written back to. The __setattr__ code was seeing the non-empty Path_ and trying to write back. At which point the code was failing. At the moment, the only workaround I can offer is, for that particular set of updates, to write directly to the underlying COM object, exposed for all wmi module objects as the .ole_object attribute. This bypasses the wmi module's __setattr__ logic and the fault .Put_ call. It's not brilliant, but it's not a great overhead, either. As a long-term fix, I'm not quite sure what to offer: there doesn't seem to be any Qualifier which would indicate whether or not an object is read-only. In principle, a WMI Property can include a "write" qualifier but that only indicates that the WMI property can be written (which, in this case, it can) rather than that the underlying object can have its properties updated. I'll try to find an object with similar behaviour closer to home which might help to narrow down the identifiable characteristics. An alternative (which would apply fairly neatly in this case) is to extend the .set method, which is designed to allow slightly neater updates of multiple attributes, to have an additional flag indicating whether or not .Put_ was to be called. TJG