From email2et at yahoo.com Fri May 2 03:08:46 2003 From: email2et at yahoo.com (ET Planet) Date: Fri May 2 05:08:51 2003 Subject: [python-win32] Conflicts with Python Message-ID: <20030502090846.25376.qmail@web20207.mail.yahoo.com> Hi, I'm new to python and using ActivePython2.2.2 on Win2K platform.Does anyone know if there's any conflict in the registry or system files when Python was installed? Apparently, whenever I did an external .exe call from a python program, the monitor just declares total darkness and only return when the process is done. Any similar experience? Thanks --------------------------------- Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20030502/bb0609d0/attachment.htm From mcfadden at ford-consulting.com Fri May 2 10:30:26 2003 From: mcfadden at ford-consulting.com (Dudley McFadden) Date: Fri May 2 12:29:38 2003 Subject: [python-win32] Conflicts with Python In-Reply-To: <20030502090846.25376.qmail@web20207.mail.yahoo.com> Message-ID: On occasion I have similar behavior when using DDE (Dynamic Data Exchange). Either pythonwin or another application blocks until the other completes some operation. Perhaps you are simultaneously running some other program that is doing its DDE operations "impolitely." I have not taken the time to identify the root cause of my problem, but it only comes up when I am dealing with DDE. ET Planet, please post details of what exactly you are doing when you say, "did an external .exe call." Okay? --dudley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20030502/87c0f311/attachment.htm From craig.taverner at comopt.com Fri May 2 23:46:42 2003 From: craig.taverner at comopt.com (Craig Taverner) Date: Fri May 2 16:44:48 2003 Subject: [python-win32] Arrays in Python Com servers Message-ID: <5D0355F204917248B054EDB0D57BD9E41C1B38@oden.comopt.com> Hi, I've recently started trying out python on windows for writing COM servers to be used in VB and C# user interfaces. I have one specific question: How do I return an array of integers or an array of floats to the VB COM client? The only documentation I really been able to find on COM servers in python has been Mark Hammonds last conference presentation, and associated samples. This covers COM clients in python more than it does COM servers. If anyone knows of some good (preferably on-line) documentation on writing COM servers, I'd love a pointer. Also, I'm interested in information on how to trigger events from Python. Again I've seen examples and discussions on how to handle events, but not on firing them. Thanks, Craig P.S. What I'm really working with is the ESRI ArcObjects library, so if anyone has experience with that, I'd be extremely pleased ;-) From craig.taverner at comopt.com Fri May 2 23:44:29 2003 From: craig.taverner at comopt.com (Craig Taverner) Date: Fri May 2 17:06:13 2003 Subject: [python-win32] Arrays in Python Com servers Message-ID: <5D0355F204917248B054EDB0D57BD9E4039CD2@oden.comopt.com> Hi, I've recently started trying out python on windows for writing COM servers to be used in VB and C# user interfaces. I have one specific question: How do I return an array of integers or an array of floats to the VB COM client? The only documentation I really been able to find on COM servers in python has been Mark Hammonds last conference presentation, and associated samples. This covers COM clients in python more than it does COM servers. If anyone knows of some good (preferably on-line) documentation on writing COM servers, I'd love a pointer. Also, I'm interested in information on how to trigger events from Python. Again I've seen examples and discussions on how to handle events, but not on firing them. Thanks, Craig P.S. What I'm really working with is the ESRI ArcObjects library, so if anyone has experience with that, I'd be extremely pleased ;-) From scottprive at earthlink.net Fri May 2 20:50:41 2003 From: scottprive at earthlink.net (Scott Prive) Date: Fri May 2 19:50:47 2003 Subject: [python-win32] Arrays in Python Com servers References: <5D0355F204917248B054EDB0D57BD9E4039CD2@oden.comopt.com> Message-ID: <034f01c31105$a490fd60$0601a8c0@scottprive.com> A partial answer to tide you over until you have a more complete response.. :-) I suggest Mark's book, Python Programming on Win32. There is quite a bit on dealing with COM. I am only 100 pages into the book, so I can't comment too much. Did you mean win32 events? I don't see that in the book anywhere (and I could be wrong). There have been some message threads on this subject I've seen in the mail archives. --Scott ----- Original Message ----- From: "Craig Taverner" To: Sent: Friday, May 02, 2003 4:44 PM Subject: [python-win32] Arrays in Python Com servers Hi, I've recently started trying out python on windows for writing COM servers to be used in VB and C# user interfaces. I have one specific question: How do I return an array of integers or an array of floats to the VB COM client? The only documentation I really been able to find on COM servers in python has been Mark Hammonds last conference presentation, and associated samples. This covers COM clients in python more than it does COM servers. If anyone knows of some good (preferably on-line) documentation on writing COM servers, I'd love a pointer. Also, I'm interested in information on how to trigger events from Python. Again I've seen examples and discussions on how to handle events, but not on firing them. Thanks, Craig P.S. What I'm really working with is the ESRI ArcObjects library, so if anyone has experience with that, I'd be extremely pleased ;-) _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 From mhammond at skippinet.com.au Sat May 3 22:17:00 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat May 3 07:18:01 2003 Subject: [python-win32] Arrays in Python Com servers In-Reply-To: <034f01c31105$a490fd60$0601a8c0@scottprive.com> Message-ID: <01fb01c31165$84d693d0$530f8490@eden> > I suggest Mark's book, Python Programming on Win32. There is > quite a bit on > dealing with COM. > I am only 100 pages into the book, so I can't comment too much. Thanks :) It should simply be a matter of returning a list (not tuple) of floats from your function. As there is no typelib, everything is dynamic, so should "just work" using any compatible type in the array you choose. > Did you mean win32 events? I don't see that in the book > anywhere (and I > could be wrong). There have been some message threads on this > subject I've > seen in the mail archives. Unfortunately, event support missed the book. Fortunately it isn't that hard - see the docstrings for win32com.client.DispatchWithEvents, or win32com\test\test_*events* Mark. From magnus at thinkware.se Sun May 4 03:45:49 2003 From: magnus at thinkware.se (Magnus =?iso-8859-1?Q?Lyck=E5?=) Date: Sat May 3 20:44:53 2003 Subject: [python-win32] Python Programming on Win32 In-Reply-To: <034f01c31105$a490fd60$0601a8c0@scottprive.com> References: <5D0355F204917248B054EDB0D57BD9E4039CD2@oden.comopt.com> Message-ID: <5.2.1.1.0.20030504023933.02682738@www.thinkware.se> At 19:50 2003-05-02 -0400, Scott Prive wrote: >I suggest Mark's book, Python Programming on Win32. BTW, that book is from January 2000, and both Python and Windows has evolved a bit since then. (Not to mention PDFgen, which has transformed into ReportLab and become a business. :^) Can we expect a second edition of that book, or are there any other Python books focused on Win32 in the pipeline? -- Magnus Lycka (It's really Lyckå), magnus@thinkware.se Thinkware AB, Sweden, www.thinkware.se I code Python ~ The shortest path from thought to working program From scottprive at earthlink.net Sat May 3 21:45:19 2003 From: scottprive at earthlink.net (Scott Prive) Date: Sat May 3 20:45:36 2003 Subject: [python-win32] Arrays in Python Com servers References: <01fb01c31165$84d693d0$530f8490@eden> Message-ID: <07cd01c311d6$711c9d00$0601a8c0@scottprive.com> ----- Original Message ----- From: "Mark Hammond" To: "'Scott Prive'" ; "'Craig Taverner'" ; Sent: Saturday, May 03, 2003 7:17 AM Subject: RE: [python-win32] Arrays in Python Com servers > > I suggest Mark's book, Python Programming on Win32. There is > > quite a bit on > > dealing with COM. > > I am only 100 pages into the book, so I can't comment too much. > > Thanks :) It should simply be a matter of returning a list (not tuple) of > floats from your function. As there is no typelib, everything is dynamic, > so should "just work" using any compatible type in the array you choose. > > > Did you mean win32 events? I don't see that in the book > > anywhere (and I > > could be wrong). There have been some message threads on this > > subject I've > > seen in the mail archives. > > Unfortunately, event support missed the book. Fortunately it isn't that > hard - see the docstrings for win32com.client.DispatchWithEvents, or > win32com\test\test_*events* > > Mark. Do you have future plans for a Second Edition? :-) What I would find *very* interesting is information how to "control" or drive other applications without COM. For example, by invoking some Application, and forcing keyboard or mouse events on that app (so you can do things like populate a File/Open dialog, etc.). Usually a software tester automates this using very expensive software like Visual Test, Silk... very expensive tools, complete overkill and come with their own language variants. From mhammond at skippinet.com.au Sun May 4 11:52:20 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat May 3 20:53:21 2003 Subject: [python-win32] RE: Python Programming on Win32 In-Reply-To: <5.2.1.1.0.20030504023933.02682738@www.thinkware.se> Message-ID: <00b401c311d7$6b39b250$530f8490@eden> > Can we expect a second edition of that book, or are there > any other Python books focused on Win32 in the pipeline? A second edition is likely to be done this year. Mark. From scottprive at earthlink.net Sat May 3 22:10:23 2003 From: scottprive at earthlink.net (Scott Prive) Date: Sat May 3 21:10:30 2003 Subject: [python-win32] Python Programming on Win32 References: <5D0355F204917248B054EDB0D57BD9E4039CD2@oden.comopt.com> <5.2.1.1.0.20030504023933.02682738@www.thinkware.se> Message-ID: <07df01c311d9$f12476a0$0601a8c0@scottprive.com> ----- Original Message ----- From: "Magnus Lyck?" To: "Mark Hammond" ; Sent: Saturday, May 03, 2003 8:45 PM Subject: [python-win32] Python Programming on Win32 > At 19:50 2003-05-02 -0400, Scott Prive wrote: > >I suggest Mark's book, Python Programming on Win32. > > BTW, that book is from January 2000, and both Python and > Windows has evolved a bit since then. (Not to mention > PDFgen, which has transformed into ReportLab and become > a business. :^) > > Can we expect a second edition of that book, or are there > any other Python books focused on Win32 in the pipeline? What a coincidence -- I just asked the same thing! :-) I suspect we'll have to wait a bit (as much as I would like to hear that assumption is wrong). Python may have changed a bit.. but it all is still valid Python. Heck, I *still* use 'import string' in regular scripts. Those kind of changes do not bother me.... 3 years is not too old for a book. The python-wn32 learning curve seems much, much easier if you come from a Visual Basic background or another Microsoft language (I don't...). So I expect this will take time for me, and I'll only scratch the surface but that's OK. This helps me avoid having to talk to .dll's... :-D From scottprive at earthlink.net Sat May 3 22:14:36 2003 From: scottprive at earthlink.net (Scott Prive) Date: Sat May 3 21:14:45 2003 Subject: [python-win32] RE: Python Programming on Win32 References: <00b401c311d7$6b39b250$530f8490@eden> Message-ID: <07f801c311da$87ff15d0$0601a8c0@scottprive.com> Nice!! I spoke too soon I guess. This is great news Mark. Any thoughts yet on what will be added? ----- Original Message ----- From: "Mark Hammond" To: "'Magnus Lycka'" ; Sent: Saturday, May 03, 2003 8:52 PM Subject: [python-win32] RE: Python Programming on Win32 > > Can we expect a second edition of that book, or are there > > any other Python books focused on Win32 in the pipeline? > > A second edition is likely to be done this year. > > Mark. > > > _______________________________________________ > Python-win32 mailing list > Python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 From craig.taverner at comopt.com Sun May 4 19:48:03 2003 From: craig.taverner at comopt.com (Craig Taverner) Date: Sun May 4 12:46:12 2003 Subject: [python-win32] Arrays in Python Com servers Message-ID: <5D0355F204917248B054EDB0D57BD9E4039CD3@oden.comopt.com> Thanks Mark, I got the arrays returned OK now, just by not specifying the type in the VB DIM statement (ie. "Dim a()" followed by "a=interface.GetArray()"). But one strange thing is that after this, UBound(a) is always one too short. I have to over-dimension the array in the python COM server by 1 element to have everything line up (it's the last element that is dropped in VB - perhaps VB uses the end of the array to store extra array info?). On the second question:- I was not able to find anything on firing win32 events from the python server in the places you suggested. I only found info on handling events in python. Is there anywhere else I can get information on firing events? What I'm after, to be precise, is the following: - VB code implements some event handler - VB code calls interface.StartCalc() on python Com object - This method does not block, but starts a thread that does some calculation - when the calculation is finished, the python fires an event that either: - sends the result array to the VB or - triggers the VB to call back into python for the result array Is this even possible in pythoncom? I'm concerned that this might require implementing some unknown interface and python does not support that. Cheers, Craig > -----Original Message----- > From: Mark Hammond [mailto:mhammond@skippinet.com.au] > Sent: den 3 maj 2003 13:17 > To: 'Scott Prive'; Craig Taverner; python-win32@python.org > Subject: RE: [python-win32] Arrays in Python Com servers > > > I suggest Mark's book, Python Programming on Win32. There is > > quite a bit on > > dealing with COM. > > I am only 100 pages into the book, so I can't comment too much. > > Thanks :) It should simply be a matter of returning a list (not tuple) of > floats from your function. As there is no typelib, everything is dynamic, > so should "just work" using any compatible type in the array you choose. > > > Did you mean win32 events? I don't see that in the book > > anywhere (and I > > could be wrong). There have been some message threads on this > > subject I've > > seen in the mail archives. > > Unfortunately, event support missed the book. Fortunately it isn't that > hard - see the docstrings for win32com.client.DispatchWithEvents, or > win32com\test\test_*events* > > Mark. From craig.taverner at comopt.com Sun May 4 19:55:48 2003 From: craig.taverner at comopt.com (Craig Taverner) Date: Sun May 4 12:53:54 2003 Subject: [python-win32] Passing COM VB objects to Python COM servers Message-ID: <5D0355F204917248B054EDB0D57BD9E4039CD4@oden.comopt.com> Hi again, I'm trying to pass a VB object to a Python COM object, that can then call methods on the VB object. Although the Python code sees the object as a PyIDispatch object, which I understand should allow me to call public methods, no methods or properties are available. Here is some example code: VB Dim interface As Object Set interface = CreateObject("Python.RasterSourceX") Dim cb As CallBack Set cb = New CallBack interface.StartCalculation cb Python def StartCalculation(self,callback): self.vb_callback=callback.QueryInterface(pythoncom.IID_IDispatch) self.vb_callback.Finished(25) # code throws exception here The VB class "CallBack" has the public method "Finished" which currently just takes an integer parameter. However, the python code seems unable to access that method. The queryinterface(IDispatch) was added later, based on some docs I read, but did nothing to help the situation. Print statements, and the trace debugging, showed the object to already be an PyIDispatch object. Is there something else I'm supposed to do to it to get IDispatch to work? Perhaps the VB class is supposed to be defined in some special way? Thanks, Craig From craig.taverner at comopt.com Sun May 4 20:00:35 2003 From: craig.taverner at comopt.com (Craig Taverner) Date: Sun May 4 12:58:41 2003 Subject: [python-win32] Re-registering python COM servers Message-ID: <5D0355F204917248B054EDB0D57BD9E4039CD5@oden.comopt.com> Hi again, I'm writing some python COM server code, but have found that I have to change the actual filename and progID of the code every time I register it for the client code (VB in this case) to see the changes I make. I've tried un-registering first before registering, but that does not help. Is there any way I can edit my python COM server code and have the changes accessible to the client without having to change the name of the source file? Interestingly enough, I do not have to change the GUID each time. A side question:- what's the best way to generate new GUIDs? Currently I use the Create GUI tool from Visual Studio. Thanks, Craig From scottprive at earthlink.net Sun May 4 17:47:44 2003 From: scottprive at earthlink.net (Scott Prive) Date: Sun May 4 16:47:56 2003 Subject: [python-win32] Re-registering python COM servers References: <5D0355F204917248B054EDB0D57BD9E4039CD5@oden.comopt.com> Message-ID: <088301c3127e$6a881bb0$0601a8c0@scottprive.com> A side question:- what's the best way to generate new GUIDs? Currently I use the Create GUI tool from Visual Studio. Thanks, Craig There's a builtin method for it: >>> import pythoncom >>> print pythoncom.CreateGuid() {guid string output here...} (example courtesy "Python Programming on Win32" page 71) -Scott From mhammond at skippinet.com.au Mon May 5 11:23:13 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sun May 4 20:24:13 2003 Subject: [python-win32] Re-registering python COM servers In-Reply-To: <5D0355F204917248B054EDB0D57BD9E4039CD5@oden.comopt.com> Message-ID: <014401c3129c$84a72310$530f8490@eden> > I'm writing some python COM server code, but have found that I have to > change the actual filename and progID of the code every time > I register > it for the client code (VB in this case) to see the changes I > make. I've > tried un-registering first before registering, but that does not help. > Is there any way I can edit my python COM server code and have the > changes accessible to the client without having to change the name of > the source file? Actually, this is a standard Python optimization. When an external program uses a COM object, a Python class is instantiated from a module (as you know). If ever that same process attempts to re-import that same module (to create another COM object), Python caches the import. You already see this in all your Python programs - no matter how many "import whatever" statements exist, it is only truly imported once, and to see changes to a module in a running Python program, you need to "reload" that module. Somehow you need to either shutdown the process, or arrange for your module to be "reloaded". One way of doing a reload is to create a Python.Interpreter COM object (one of the win32com demos), and ask it to exec "import yourmod;reload(yourmod)". I agree it would be nice to have win32com handle this magically, but I am not sure how to expose this. Mark. -------------- next part -------------- A non-text attachment was scrubbed... Name: winmail.dat Type: application/ms-tnef Size: 2280 bytes Desc: not available Url : http://mail.python.org/pipermail/python-win32/attachments/20030505/178cf287/winmail.bin From rasjidw at openminddev.net Mon May 5 23:12:39 2003 From: rasjidw at openminddev.net (Rasjid Wilcox) Date: Mon May 5 08:12:47 2003 Subject: [python-win32] py2exe question In-Reply-To: <5.2.1.1.0.20030430024349.02693ac0@www.thinkware.se> References: <5.2.1.1.0.20030430024349.02693ac0@www.thinkware.se> Message-ID: <200305052212.39345.rasjidw@openminddev.net> On Wednesday 30 April 2003 10:59, Magnus Lyck? wrote: > In Unix you would also have the possibility to make > links with different names to handler.exe, and let it > work like this instead: > > > # handler.py > import os, a, b, c > f = os.environ() > action = f['SCRIPT_NAME'].split('/')[-1] > > if action in ['a', 'b', 'c']: > locals()[action].main() > > > Then you you wouldn't have to change the URLs, but > unfortunately, Windows shortcuts aren't anywhere near > as useful as hard or symbolic links in Unix. If you install Cygwin, you can get real multiple hardlinks in Windows too, which work with ordinary Windows programs (like Notepad etc). Hardlink a.txt to b.txt in Cygwin, and then when you edit a.txt, b.txt changes too, but both look link ordinary files to Windows. It is very cool, and possibly even useful occasionally. :-) Rasjid. -- Rasjid Wilcox Canberra, Australia UTC + 10 http://www.openminddev.net From scottprive at earthlink.net Mon May 5 10:46:32 2003 From: scottprive at earthlink.net (Scott Prive) Date: Mon May 5 09:46:48 2003 Subject: [python-win32] py2exe question References: <5.2.1.1.0.20030430024349.02693ac0@www.thinkware.se> <200305052212.39345.rasjidw@openminddev.net> Message-ID: <000901c3130c$bdf4acd0$0601a8c0@scottprive.com> ----- Original Message ----- From: "Rasjid Wilcox" To: "Magnus Lyck?" ; "sense gin" Cc: Sent: Monday, May 05, 2003 8:12 AM Subject: Re: [python-win32] py2exe question On Wednesday 30 April 2003 10:59, Magnus Lyck? wrote: > In Unix you would also have the possibility to make > links with different names to handler.exe, and let it > work like this instead: > > > # handler.py > import os, a, b, c > f = os.environ() > action = f['SCRIPT_NAME'].split('/')[-1] > > if action in ['a', 'b', 'c']: > locals()[action].main() > > > Then you you wouldn't have to change the URLs, but > unfortunately, Windows shortcuts aren't anywhere near > as useful as hard or symbolic links in Unix. If you install Cygwin, you can get real multiple hardlinks in Windows too, which work with ordinary Windows programs (like Notepad etc). Hardlink a.txt to b.txt in Cygwin, and then when you edit a.txt, b.txt changes too, but both look link ordinary files to Windows. It is very cool, and possibly even useful occasionally. :-) Rasjid. Cygwin is really cool stuff. One word of warning: Cygwin (and the Python version optional with it) only understands "unix style" /some/path/t/foo You can install Cygwin (with Python) and it will not interfere with your existing Python install. More complicated, but you can even use just Cygwin (w/o their Python) and use your "existing" Python interpreter, if you investigate the Cygwin tool called "cygpath", and use it to write a small BAT or sh wrapper around python.exe and other bits (see cygwin list archive). -Scott From tony at tcapp.com Mon May 5 18:01:16 2003 From: tony at tcapp.com (Tony Cappellini) Date: Mon May 5 20:01:28 2003 Subject: [python-win32] CLosing/Shutting down a COM application, started from a Python program In-Reply-To: Message-ID: <20030505165732.R98872-100000@yamato.yamato.com> I've looked through Mark Hammond's book, as well as some of the COM tutorials, and found that this is used to start an aplication through COM import win32com.client > xl=win32com.client.Dispatch("") This works quite well for my sitatuion. What I could not find is how to terminate/close that same application from the same Python program, via COM. I don't want to thave to go to the application itself, and chose File/Exit. Is there a way to close the program via COM ? thanks From mhammond at skippinet.com.au Tue May 6 12:15:44 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon May 5 21:16:44 2003 Subject: [python-win32] CLosing/Shutting down a COM application, started from a Python program In-Reply-To: <20030505165732.R98872-100000@yamato.yamato.com> Message-ID: <02b501c3136d$0532e390$530f8490@eden> > Is there a way to close the program via COM ? It depends on the object. If you release the last reference to an application, it may close. You release a reference by setting the object to None, and can use pythoncom._GetInterfaceCount() to ensure there are no references hiding. However, some apps wont shutdown, most notably MS Office whenever the "Visible" property is set to True. Office apps have a "Quit" method, and I believe that resetting them to invisible then removing all references also works. Certainly Word and Excel etc all shutdown correctly if you never set Visible to True and delete all your references. Mark. From larryl at imail.EECS.Berkeley.EDU Wed May 7 11:53:33 2003 From: larryl at imail.EECS.Berkeley.EDU (Lawrence W. Leung) Date: Wed May 7 14:32:12 2003 Subject: [python-win32] os.system problem Message-ID: Hi, I'm trying to use os.system to execute a command in win2k with python 2.2.2 and it's not behaving as expected. Basically, the idea is I pass it a command line that begins with a quoted path to an executable (to avoid the problem of the space in the path) and also a quoted argument and it fails to find the executable. But oddly enough when I unquote the argument it seems to find the executable just fine. I've been playing with this for quite a while now and I'm starting to suspect it's a python bug. When I print out my command, it shows up fine. I can even copy that into a cmd.exe window and have it run fine. But when I run it with python and it doesn't work. Can someone try to reproduce this problem to check if it's really a bug? Here's a simplified test case using cygwin's grep: 1. copy grep.exe into a new folder "test folder" in your cygwin dir. 2. in python, os.chdir() into the cygwin dir. 3. os.system('test folder/grep.exe') returns 1 for me (can't find exe) 4. os.system('"test folder/grep.exe"') returns 128 for me (grep can't find a cygwin dll 5. os.system('"test folder/grep.exe" --?') returns 128 for me (as expected) 6. os.system('"test folder/grep.exe" "bleh"') returns 1 for me!! (command not found!) Thanks, ---- -Larry On Tue, 6 May 2003, Raymond Hettinger wrote: > Hello Larry, > > Using quotes and escape characters can work but that is > taking the hard around. > > I recommend several things that will simplify solving problems > like this. > > First, get the string logic right (verified with a print > statement) before adding the os.system command and trying > to guess what was sent to the interpreter. > > Second, debug your string logic using the interactive interpreter. > This is the easiest way to see what works and avoids having > to use print to see what is going on. > > Third, avoid escape character issues by using either: > - raw strings: r"the \quick" > - outer quotes of a different type 'he said hello" to me' > - triple quotes """Here are the "do's and don'ts" of quoting""" > > Taken together the three ideas ought to make the problem trivial: > > >>> command = 'c:/program files/utils/grep "' > >>> command > 'c:/program files/utils/grep "' > >>> argument = 'search text' > >>> argument > 'search text' > >>> fullcommand = command + argument + '"' > >>> fullcommand > 'c:/program files/utils/grep "search text"' > >>> import os > >>> os.system(fullcommand) > > > > Raymond Hettinger > > > > ----- Original Message ----- > From: "Lawrence W. Leung" > To: > Cc: "Lawrence W. Leung" > Sent: Tuesday, May 06, 2003 5:34 PM > Subject: Re: [Python-Help] os.system problem > > > > Sorry, I think you misunderstood me. > > > > The full code to build the command looks something like this: > > COMMAND = "\"C:/Program Files/...exe\"" > > os.system(COMMAND+" \"argument\"") > > > > It shouldn't matter that I'm using quotes and escape chars right? > > Thanks, > > -Larry > > > > > > I'm using 2.2.2 on windows and I noticed that os.system doesn't > > > > seem to be working like a command line would. > > > > > > > If i call: "C:/Program Files/...some.exe", it works > > > > If i call: "C:/Program Files/...some.exe" some arguments, it works > > > > but if I call: "C:/Program Files/...some.exe" > > > > "some-argument-in-quotes", > > > > it complains about not being able to find the executable C:/Program > > > > > > Python can use either single or double quotes (actually, it can use > > > triple-quotes too). So something like: > > > > > > cmd='c:/Program Files/wibble.exe "args"' > > > os.system(cmd) > > > > > > ought to work. > > > > > > Regards, > > > Matt > > > > > > > > > > > > _______________________________________________ > > Python-Help maillist - Python-Help@python.org > > http://mail.python.org/mailman/listinfo/python-help > > ################################################################# > ################################################################# > ################################################################# > ##### > ##### > ##### > ################################################################# > ################################################################# > ################################################################# > From jens.jorgensen at tallan.com Wed May 7 16:04:58 2003 From: jens.jorgensen at tallan.com (Jens B. Jorgensen) Date: Wed May 7 16:05:18 2003 Subject: [python-win32] os.system problem In-Reply-To: References: Message-ID: <3EB966EA.6060409@tallan.com> Things seem to work fine for me: jbj1@tallan2 /c/temp $ mkdir /c/cygwin/test\ folder jbj1@tallan2 /c/temp $ cp /usr/bin/grep.exe /c/cygwin/test\ folder/ jbj1@tallan2 /c/temp $ python ActivePython 2.2.2 Build 224 (ActiveState Corp.) based on Python 2.2.2 (#37, Nov 26 2002, 10:24:37) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.chdir('/cygwin') >>> os.system('test folder/grep.exe') 0 >>> os.system('"test folder/grep.exe"') Usage: grep [OPTION]... PATTERN [FILE]... Try `grep --help' for more information. 2 >>> os.system('"test folder/grep.exe" --?') grep: unknown option -- ? Usage: grep [OPTION]... PATTERN [FILE]... Try `grep --help' for more information. 2 >>> os.system('"test folder/grep.exe" "bleh"') 0 >>> Are you using cygwin's python or ActiveState's? Lawrence W. Leung wrote: >Hi, > >I'm trying to use os.system to execute a command in win2k with python >2.2.2 and it's not behaving as expected. Basically, the idea is I pass it >a command line that begins with a quoted path to an executable (to avoid >the problem of the space in the path) and also a quoted argument and it >fails to find the executable. But oddly enough when I unquote the >argument it seems to find the executable just fine. > >I've been playing with this for quite a while now and I'm starting to >suspect it's a python bug. When I print out my command, it shows up fine. >I can even copy that into a cmd.exe window and have it run fine. But when >I run it with python and it doesn't work. Can someone try to reproduce >this problem to check if it's really a bug? > >Here's a simplified test case using cygwin's grep: >1. copy grep.exe into a new folder "test folder" in your cygwin dir. >2. in python, os.chdir() into the cygwin dir. >3. os.system('test folder/grep.exe') returns 1 for me (can't find exe) >4. os.system('"test folder/grep.exe"') returns 128 for me (grep can't find >a cygwin dll >5. os.system('"test folder/grep.exe" --?') returns 128 for me (as >expected) >6. os.system('"test folder/grep.exe" "bleh"') returns 1 for me!! (command >not found!) > >Thanks, >---- >-Larry > >On Tue, 6 May 2003, Raymond Hettinger wrote: > > > >>Hello Larry, >> >>Using quotes and escape characters can work but that is >>taking the hard around. >> >>I recommend several things that will simplify solving problems >>like this. >> >>First, get the string logic right (verified with a print >>statement) before adding the os.system command and trying >>to guess what was sent to the interpreter. >> >>Second, debug your string logic using the interactive interpreter. >>This is the easiest way to see what works and avoids having >>to use print to see what is going on. >> >>Third, avoid escape character issues by using either: >> - raw strings: r"the \quick" >> - outer quotes of a different type 'he said hello" to me' >> - triple quotes """Here are the "do's and don'ts" of quoting""" >> >>Taken together the three ideas ought to make the problem trivial: >> >> >> >>>>>command = 'c:/program files/utils/grep "' >>>>>command >>>>> >>>>> >>'c:/program files/utils/grep "' >> >> >>>>>argument = 'search text' >>>>>argument >>>>> >>>>> >>'search text' >> >> >>>>>fullcommand = command + argument + '"' >>>>>fullcommand >>>>> >>>>> >>'c:/program files/utils/grep "search text"' >> >> >>>>>import os >>>>>os.system(fullcommand) >>>>> >>>>> >> >>Raymond Hettinger >> >> >> >>----- Original Message ----- >>From: "Lawrence W. Leung" >>To: >>Cc: "Lawrence W. Leung" >>Sent: Tuesday, May 06, 2003 5:34 PM >>Subject: Re: [Python-Help] os.system problem >> >> >> >> >>>Sorry, I think you misunderstood me. >>> >>>The full code to build the command looks something like this: >>>COMMAND = "\"C:/Program Files/...exe\"" >>>os.system(COMMAND+" \"argument\"") >>> >>>It shouldn't matter that I'm using quotes and escape chars right? >>>Thanks, >>>-Larry >>> >>> >>> >>>>>I'm using 2.2.2 on windows and I noticed that os.system doesn't >>>>>seem to be working like a command line would. >>>>> >>>>> >>>>>If i call: "C:/Program Files/...some.exe", it works >>>>>If i call: "C:/Program Files/...some.exe" some arguments, it works >>>>>but if I call: "C:/Program Files/...some.exe" >>>>>"some-argument-in-quotes", >>>>>it complains about not being able to find the executable C:/Program >>>>> >>>>> >>>>Python can use either single or double quotes (actually, it can use >>>>triple-quotes too). So something like: >>>> >>>>cmd='c:/Program Files/wibble.exe "args"' >>>>os.system(cmd) >>>> >>>>ought to work. >>>> >>>>Regards, >>>>Matt >>>> >>>> >>>> >>>> >>>_______________________________________________ >>>Python-Help maillist - Python-Help@python.org >>>http://mail.python.org/mailman/listinfo/python-help >>> >>> >>################################################################# >>################################################################# >>################################################################# >>##### >>##### >>##### >>################################################################# >>################################################################# >>################################################################# >> >> >> > > > >_______________________________________________ >Python-win32 mailing list >Python-win32@python.org >http://mail.python.org/mailman/listinfo/python-win32 > > -- Jens B. Jorgensen jens.jorgensen@tallan.com "With a focused commitment to our clients and our people, we deliver value through customized technology solutions" From larryl at imail.EECS.Berkeley.EDU Wed May 7 14:23:47 2003 From: larryl at imail.EECS.Berkeley.EDU (Lawrence W. Leung) Date: Wed May 7 16:40:14 2003 Subject: [python-win32] os.system problem In-Reply-To: <3EB966EA.6060409@tallan.com> Message-ID: I've tested it on another machine with the same python 2.2.2 version and I still get the problem with os.system. I'm using the version of python off python.org which doesn't appear to be activestate's: Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. Here is what I did after copying grep.exe into "test folder": >>> os.system('"test folder/bleh"') 0 >>> os.system('"test folder/grep.exe"') Usage: grep [OPTION]... PATTERN [FILE]... Try `grep --help' for more information. 2 >>> os.system('"test folder/grep.exe" --?') test folder/grep: unrecognized option `--?' Usage: grep [OPTION]... PATTERN [FILE]... Try `grep --help' for more information. 2 >>> os.system('"test folder/grep.exe" "--?"') 0 Just to verify that it isn't grep's fault I tried it in cmd: C:\cygwin>"test folder/grep.exe" "--?" test folder/grep: unrecognized option `--?' Usage: grep [OPTION]... PATTERN [FILE]... Try `grep --help' for more information. Perhaps the build linked off python.org has a bug?? Thanks, -------------- -Larry On Wed, 7 May 2003, Jens B. Jorgensen wrote: > Things seem to work fine for me: > > jbj1@tallan2 /c/temp > $ mkdir /c/cygwin/test\ folder > > jbj1@tallan2 /c/temp > $ cp /usr/bin/grep.exe /c/cygwin/test\ folder/ > > jbj1@tallan2 /c/temp > $ python > ActivePython 2.2.2 Build 224 (ActiveState Corp.) based on > Python 2.2.2 (#37, Nov 26 2002, 10:24:37) [MSC 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import os > >>> os.chdir('/cygwin') > >>> os.system('test folder/grep.exe') > 0 > >>> os.system('"test folder/grep.exe"') > Usage: grep [OPTION]... PATTERN [FILE]... > Try `grep --help' for more information. > 2 > >>> os.system('"test folder/grep.exe" --?') > grep: unknown option -- ? > Usage: grep [OPTION]... PATTERN [FILE]... > Try `grep --help' for more information. > 2 > >>> os.system('"test folder/grep.exe" "bleh"') > 0 > >>> > > Are you using cygwin's python or ActiveState's? > > Lawrence W. Leung wrote: > > >Hi, > > > >I'm trying to use os.system to execute a command in win2k with python > >2.2.2 and it's not behaving as expected. Basically, the idea is I pass it > >a command line that begins with a quoted path to an executable (to avoid > >the problem of the space in the path) and also a quoted argument and it > >fails to find the executable. But oddly enough when I unquote the > >argument it seems to find the executable just fine. > > > >I've been playing with this for quite a while now and I'm starting to > >suspect it's a python bug. When I print out my command, it shows up fine. > >I can even copy that into a cmd.exe window and have it run fine. But when > >I run it with python and it doesn't work. Can someone try to reproduce > >this problem to check if it's really a bug? > > > >Here's a simplified test case using cygwin's grep: > >1. copy grep.exe into a new folder "test folder" in your cygwin dir. > >2. in python, os.chdir() into the cygwin dir. > >3. os.system('test folder/grep.exe') returns 1 for me (can't find exe) > >4. os.system('"test folder/grep.exe"') returns 128 for me (grep can't find > >a cygwin dll > >5. os.system('"test folder/grep.exe" --?') returns 128 for me (as > >expected) > >6. os.system('"test folder/grep.exe" "bleh"') returns 1 for me!! (command > >not found!) > > > >Thanks, > >---- > >-Larry > > > >On Tue, 6 May 2003, Raymond Hettinger wrote: > > > > > > > >>Hello Larry, > >> > >>Using quotes and escape characters can work but that is > >>taking the hard around. > >> > >>I recommend several things that will simplify solving problems > >>like this. > >> > >>First, get the string logic right (verified with a print > >>statement) before adding the os.system command and trying > >>to guess what was sent to the interpreter. > >> > >>Second, debug your string logic using the interactive interpreter. > >>This is the easiest way to see what works and avoids having > >>to use print to see what is going on. > >> > >>Third, avoid escape character issues by using either: > >> - raw strings: r"the \quick" > >> - outer quotes of a different type 'he said hello" to me' > >> - triple quotes """Here are the "do's and don'ts" of quoting""" > >> > >>Taken together the three ideas ought to make the problem trivial: > >> > >> > >> > >>>>>command = 'c:/program files/utils/grep "' > >>>>>command > >>>>> > >>>>> > >>'c:/program files/utils/grep "' > >> > >> > >>>>>argument = 'search text' > >>>>>argument > >>>>> > >>>>> > >>'search text' > >> > >> > >>>>>fullcommand = command + argument + '"' > >>>>>fullcommand > >>>>> > >>>>> > >>'c:/program files/utils/grep "search text"' > >> > >> > >>>>>import os > >>>>>os.system(fullcommand) > >>>>> > >>>>> > >> > >>Raymond Hettinger > >> > >> > >> > >>----- Original Message ----- > >>From: "Lawrence W. Leung" > >>To: > >>Cc: "Lawrence W. Leung" > >>Sent: Tuesday, May 06, 2003 5:34 PM > >>Subject: Re: [Python-Help] os.system problem > >> > >> > >> > >> > >>>Sorry, I think you misunderstood me. > >>> > >>>The full code to build the command looks something like this: > >>>COMMAND = "\"C:/Program Files/...exe\"" > >>>os.system(COMMAND+" \"argument\"") > >>> > >>>It shouldn't matter that I'm using quotes and escape chars right? > >>>Thanks, > >>>-Larry > >>> > >>> > >>> > >>>>>I'm using 2.2.2 on windows and I noticed that os.system doesn't > >>>>>seem to be working like a command line would. > >>>>> > >>>>> > >>>>>If i call: "C:/Program Files/...some.exe", it works > >>>>>If i call: "C:/Program Files/...some.exe" some arguments, it works > >>>>>but if I call: "C:/Program Files/...some.exe" > >>>>>"some-argument-in-quotes", > >>>>>it complains about not being able to find the executable C:/Program > >>>>> > >>>>> > >>>>Python can use either single or double quotes (actually, it can use > >>>>triple-quotes too). So something like: > >>>> > >>>>cmd='c:/Program Files/wibble.exe "args"' > >>>>os.system(cmd) > >>>> > >>>>ought to work. > >>>> > >>>>Regards, > >>>>Matt > >>>> > >>>> > >>>> > >>>> > >>>_______________________________________________ > >>>Python-Help maillist - Python-Help@python.org > >>>http://mail.python.org/mailman/listinfo/python-help > >>> > >>> > >>################################################################# > >>################################################################# > >>################################################################# > >>##### > >>##### > >>##### > >>################################################################# > >>################################################################# > >>################################################################# > >> > >> > >> > > > > > > > >_______________________________________________ > >Python-win32 mailing list > >Python-win32@python.org > >http://mail.python.org/mailman/listinfo/python-win32 > > > > > > -- > Jens B. Jorgensen > jens.jorgensen@tallan.com > > "With a focused commitment to our clients and our people, we deliver value through customized technology solutions" > > > From rasjidw at openminddev.net Thu May 8 22:55:56 2003 From: rasjidw at openminddev.net (Rasjid Wilcox) Date: Thu May 8 07:56:05 2003 Subject: [python-win32] py2exe question In-Reply-To: <200305052212.39345.rasjidw@openminddev.net> References: <5.2.1.1.0.20030430024349.02693ac0@www.thinkware.se> <200305052212.39345.rasjidw@openminddev.net> Message-ID: <200305082155.56673.rasjidw@openminddev.net> On Monday 05 May 2003 22:12, Rasjid Wilcox wrote: > > If you install Cygwin, you can get real multiple hardlinks in Windows too, > which work with ordinary Windows programs (like Notepad etc). > > Hardlink a.txt to b.txt in Cygwin, and then when you edit a.txt, b.txt > changes too, but both look link ordinary files to Windows. For the record, it turns out that this only seems to work on an NTFS filesystem, not a FAT32 filesystem. -- Rasjid Wilcox Canberra, Australia UTC + 10 http://www.openminddev.net From scottprive at earthlink.net Thu May 8 09:21:02 2003 From: scottprive at earthlink.net (Scott Prive) Date: Thu May 8 08:21:08 2003 Subject: [python-win32] os.system problem References: Message-ID: <002501c3155c$4acf73f0$0601a8c0@scottprive.com> Been there :-) Lawrence, try this: 1) Know that Cygwin executables will only understand UNIX-style pathing: /path/to/foobar You CAN invoke these utilities from a CMD.EXE shell, or say Python... but the above is still true: things like path arguments need to be in /a/b/c style. Lots of users in the cygwin mailing list have fallen into this trap (inc. me). Use UNIX-style pathing. You can also experiment some with the Cygwin utility "cygpath", but you'll need to be creative and find a solution using it. 2) This really helped me: Create a dummy shell script called foo.sh. The only logic this script should have is: echo $0 $1 $2 $3 etc. Now call this shell command from Python *exactly* how you were calling your other, problematic command. You should spot the error. What's likely happening is your strings are unescaped TWICE... once in python, and once by CMD.EXE before it arrives at your target command (at least, that's how it works the way I was calling things from Cygwin Perl). For me I had to change my strings to (ex): "net use \\\\\\\\servername\\\\share X: user@domain" Also, there may be a way in Python to "directly" call commands, without handing the job off to a shell process. Had I done that, I would have avoided the shell completely and could have done: \\\\server\\share .... It's been a while and I might have a slight error in the above, but the technique for validating what your command "really" sees is valid, and so is the escaping requirements. The dummy shell command is key because it is very difficult to debug what shell commands "really" see when invoked... most will simply return usage errors, and not dump what it is they were asked to do. -Scott ----- Original Message ----- From: "Lawrence W. Leung" To: Sent: Wednesday, May 07, 2003 1:53 PM Subject: [python-win32] os.system problem > Hi, > > I'm trying to use os.system to execute a command in win2k with python > 2.2.2 and it's not behaving as expected. Basically, the idea is I pass it > a command line that begins with a quoted path to an executable (to avoid > the problem of the space in the path) and also a quoted argument and it > fails to find the executable. But oddly enough when I unquote the > argument it seems to find the executable just fine. > > I've been playing with this for quite a while now and I'm starting to > suspect it's a python bug. When I print out my command, it shows up fine. > I can even copy that into a cmd.exe window and have it run fine. But when > I run it with python and it doesn't work. Can someone try to reproduce > this problem to check if it's really a bug? > > Here's a simplified test case using cygwin's grep: > 1. copy grep.exe into a new folder "test folder" in your cygwin dir. > 2. in python, os.chdir() into the cygwin dir. > 3. os.system('test folder/grep.exe') returns 1 for me (can't find exe) > 4. os.system('"test folder/grep.exe"') returns 128 for me (grep can't find > a cygwin dll > 5. os.system('"test folder/grep.exe" --?') returns 128 for me (as > expected) > 6. os.system('"test folder/grep.exe" "bleh"') returns 1 for me!! (command > not found!) > > Thanks, > ---- > -Larry > > On Tue, 6 May 2003, Raymond Hettinger wrote: > > > Hello Larry, > > > > Using quotes and escape characters can work but that is > > taking the hard around. > > > > I recommend several things that will simplify solving problems > > like this. > > > > First, get the string logic right (verified with a print > > statement) before adding the os.system command and trying > > to guess what was sent to the interpreter. > > > > Second, debug your string logic using the interactive interpreter. > > This is the easiest way to see what works and avoids having > > to use print to see what is going on. > > > > Third, avoid escape character issues by using either: > > - raw strings: r"the \quick" > > - outer quotes of a different type 'he said hello" to me' > > - triple quotes """Here are the "do's and don'ts" of quoting""" > > > > Taken together the three ideas ought to make the problem trivial: > > > > >>> command = 'c:/program files/utils/grep "' > > >>> command > > 'c:/program files/utils/grep "' > > >>> argument = 'search text' > > >>> argument > > 'search text' > > >>> fullcommand = command + argument + '"' > > >>> fullcommand > > 'c:/program files/utils/grep "search text"' > > >>> import os > > >>> os.system(fullcommand) > > > > > > > > Raymond Hettinger > > > > > > > > ----- Original Message ----- > > From: "Lawrence W. Leung" > > To: > > Cc: "Lawrence W. Leung" > > Sent: Tuesday, May 06, 2003 5:34 PM > > Subject: Re: [Python-Help] os.system problem > > > > > > > Sorry, I think you misunderstood me. > > > > > > The full code to build the command looks something like this: > > > COMMAND = "\"C:/Program Files/...exe\"" > > > os.system(COMMAND+" \"argument\"") > > > > > > It shouldn't matter that I'm using quotes and escape chars right? > > > Thanks, > > > -Larry > > > > > > > > I'm using 2.2.2 on windows and I noticed that os.system doesn't > > > > > seem to be working like a command line would. > > > > > > > > > If i call: "C:/Program Files/...some.exe", it works > > > > > If i call: "C:/Program Files/...some.exe" some arguments, it works > > > > > but if I call: "C:/Program Files/...some.exe" > > > > > "some-argument-in-quotes", > > > > > it complains about not being able to find the executable C:/Program > > > > > > > > Python can use either single or double quotes (actually, it can use > > > > triple-quotes too). So something like: > > > > > > > > cmd='c:/Program Files/wibble.exe "args"' > > > > os.system(cmd) > > > > > > > > ought to work. > > > > > > > > Regards, > > > > Matt > > > > > > > > > > > > > > > > > _______________________________________________ > > > Python-Help maillist - Python-Help@python.org > > > http://mail.python.org/mailman/listinfo/python-help > > > > ################################################################# > > ################################################################# > > ################################################################# > > ##### > > ##### > > ##### > > ################################################################# > > ################################################################# > > ################################################################# > > > > > > _______________________________________________ > Python-win32 mailing list > Python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 From scottprive at earthlink.net Thu May 8 09:27:18 2003 From: scottprive at earthlink.net (Scott Prive) Date: Thu May 8 08:27:30 2003 Subject: [python-win32] os.system problem References: <002501c3155c$4acf73f0$0601a8c0@scottprive.com> Message-ID: <003c01c3155d$2b114600$0601a8c0@scottprive.com> I should have read the entire thread before replying..... My "use unix pathing" advice goes if you were using Cygwin Python. You're not. (You can have both on your system and they will not conflict, as long as you don't put Cygwin stuff in your PATH... which I don't reccomend) The versions of Python from python.org and Activestate both understand windows-style pathing. There will be no differences there, but again, Cygwin utilities might behave strange. A dummy-script to dump what you pass it will be helpful I believe. ----- Original Message ----- From: "Scott Prive" To: "Lawrence W. Leung" ; Sent: Thursday, May 08, 2003 8:21 AM Subject: Re: [python-win32] os.system problem > Been there :-) > > Lawrence, try this: > > 1) Know that Cygwin executables will only understand UNIX-style pathing: > /path/to/foobar > You CAN invoke these utilities from a CMD.EXE shell, or say Python... but > the above is still true: things like path arguments need to be in /a/b/c > style. Lots of users in the cygwin mailing list have fallen into this trap > (inc. me). > > Use UNIX-style pathing. You can also experiment some with the Cygwin utility > "cygpath", but you'll need to be creative and find a solution using it. > > 2) This really helped me: > > Create a dummy shell script called foo.sh. The only logic this script should > have is: > echo $0 $1 $2 $3 etc. > > Now call this shell command from Python *exactly* how you were calling your > other, problematic command. You should spot the error. > > What's likely happening is your strings are unescaped TWICE... once in > python, and once by CMD.EXE before it arrives at your target command (at > least, that's how it works the way I was calling things from Cygwin Perl). > For me I had to change my strings to (ex): "net use > \\\\\\\\servername\\\\share X: user@domain" > > Also, there may be a way in Python to "directly" call commands, without > handing the job off to a shell process. Had I done that, I would have > avoided the shell completely and could have done: \\\\server\\share .... > > It's been a while and I might have a slight error in the above, but the > technique for validating what your command "really" sees is valid, and so is > the escaping requirements. The dummy shell command is key because it is very > difficult to debug what shell commands "really" see when invoked... most > will simply return usage errors, and not dump what it is they were asked to > do. > > -Scott > > > > ----- Original Message ----- > From: "Lawrence W. Leung" > To: > Sent: Wednesday, May 07, 2003 1:53 PM > Subject: [python-win32] os.system problem > > > > Hi, > > > > I'm trying to use os.system to execute a command in win2k with python > > 2.2.2 and it's not behaving as expected. Basically, the idea is I pass it > > a command line that begins with a quoted path to an executable (to avoid > > the problem of the space in the path) and also a quoted argument and it > > fails to find the executable. But oddly enough when I unquote the > > argument it seems to find the executable just fine. > > > > I've been playing with this for quite a while now and I'm starting to > > suspect it's a python bug. When I print out my command, it shows up fine. > > I can even copy that into a cmd.exe window and have it run fine. But when > > I run it with python and it doesn't work. Can someone try to reproduce > > this problem to check if it's really a bug? > > > > Here's a simplified test case using cygwin's grep: > > 1. copy grep.exe into a new folder "test folder" in your cygwin dir. > > 2. in python, os.chdir() into the cygwin dir. > > 3. os.system('test folder/grep.exe') returns 1 for me (can't find exe) > > 4. os.system('"test folder/grep.exe"') returns 128 for me (grep can't find > > a cygwin dll > > 5. os.system('"test folder/grep.exe" --?') returns 128 for me (as > > expected) > > 6. os.system('"test folder/grep.exe" "bleh"') returns 1 for me!! (command > > not found!) > > > > Thanks, > > ---- > > -Larry > > > > On Tue, 6 May 2003, Raymond Hettinger wrote: > > > > > Hello Larry, > > > > > > Using quotes and escape characters can work but that is > > > taking the hard around. > > > > > > I recommend several things that will simplify solving problems > > > like this. > > > > > > First, get the string logic right (verified with a print > > > statement) before adding the os.system command and trying > > > to guess what was sent to the interpreter. > > > > > > Second, debug your string logic using the interactive interpreter. > > > This is the easiest way to see what works and avoids having > > > to use print to see what is going on. > > > > > > Third, avoid escape character issues by using either: > > > - raw strings: r"the \quick" > > > - outer quotes of a different type 'he said hello" to me' > > > - triple quotes """Here are the "do's and don'ts" of quoting""" > > > > > > Taken together the three ideas ought to make the problem trivial: > > > > > > >>> command = 'c:/program files/utils/grep "' > > > >>> command > > > 'c:/program files/utils/grep "' > > > >>> argument = 'search text' > > > >>> argument > > > 'search text' > > > >>> fullcommand = command + argument + '"' > > > >>> fullcommand > > > 'c:/program files/utils/grep "search text"' > > > >>> import os > > > >>> os.system(fullcommand) > > > > > > > > > > > > Raymond Hettinger > > > > > > > > > > > > ----- Original Message ----- > > > From: "Lawrence W. Leung" > > > To: > > > Cc: "Lawrence W. Leung" > > > Sent: Tuesday, May 06, 2003 5:34 PM > > > Subject: Re: [Python-Help] os.system problem > > > > > > > > > > Sorry, I think you misunderstood me. > > > > > > > > The full code to build the command looks something like this: > > > > COMMAND = "\"C:/Program Files/...exe\"" > > > > os.system(COMMAND+" \"argument\"") > > > > > > > > It shouldn't matter that I'm using quotes and escape chars right? > > > > Thanks, > > > > -Larry > > > > > > > > > > I'm using 2.2.2 on windows and I noticed that os.system doesn't > > > > > > seem to be working like a command line would. > > > > > > > > > > > If i call: "C:/Program Files/...some.exe", it works > > > > > > If i call: "C:/Program Files/...some.exe" some arguments, it works > > > > > > but if I call: "C:/Program Files/...some.exe" > > > > > > "some-argument-in-quotes", > > > > > > it complains about not being able to find the executable > C:/Program > > > > > > > > > > Python can use either single or double quotes (actually, it can use > > > > > triple-quotes too). So something like: > > > > > > > > > > cmd='c:/Program Files/wibble.exe "args"' > > > > > os.system(cmd) > > > > > > > > > > ought to work. > > > > > > > > > > Regards, > > > > > Matt > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > Python-Help maillist - Python-Help@python.org > > > > http://mail.python.org/mailman/listinfo/python-help > > > > > > ################################################################# > > > ################################################################# > > > ################################################################# > > > ##### > > > ##### > > > ##### > > > ################################################################# > > > ################################################################# > > > ################################################################# > > > > > > > > > > > _______________________________________________ > > Python-win32 mailing list > > Python-win32@python.org > > http://mail.python.org/mailman/listinfo/python-win32 > > > _______________________________________________ > Python-win32 mailing list > Python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 From amapy at snafu.de Thu May 8 23:04:13 2003 From: amapy at snafu.de (Andreas Maurer) Date: Thu May 8 16:04:19 2003 Subject: [python-win32] python and COM - in particular Visual SourceSafe Automation and python Message-ID: <3EBAB83D.2000504@snafu.de> Hi everybody, I've a question about a strange behavior about comparing Visual Basic and python. Don't worry ;-) I used Visual SourceSafe under python with teh SourceSafe COM-Server --> oVSS = win32com.client.Dispatch('SourceSafe'). Everything works fine. I accomplished the makepy-utility and for the VSSItem-object the GetVersion method was available. When I try the same in Visual Basic I cant't see the VSSItem.GetVersion(...) method. Why does python and win32com find this method in the right way and how does makepy work, that this important method is available under python and not under VB? I will be very appreciated for any hints to solve this mystery Andi From magnus at thinkware.se Fri May 9 00:43:50 2003 From: magnus at thinkware.se (Magnus =?iso-8859-1?Q?Lyck=E5?=) Date: Thu May 8 17:42:04 2003 Subject: [python-win32] os.system problem In-Reply-To: Message-ID: <5.2.1.1.0.20030508233300.0260d120@www.thinkware.se> At 10:53 2003-05-07 -0700, Lawrence W. Leung wrote: >Hi, > >I'm trying to use os.system to execute a command in win2k with python >2.2.2 and it's not behaving as expected. Basically, the idea is I pass it >a command line that begins with a quoted path to an executable (to avoid >the problem of the space in the path) and also a quoted argument and it >fails to find the executable. But oddly enough when I unquote the >argument it seems to find the executable just fine. Doesn't the same thing happen if you run these things directly from the command line? It's my experience in Windows that I have to remove quotes that I would be using if I was in Unix. In Unix, the shell will remove the quotes before calling commands. The quotes will determine if a parameter is just one parameter, despite containing spaces etc, and single quotes will stop expansion of $ etc, but Windows don't have these things. Whatever you type at the command line will be thrown at your program, quotes and all. Unix utilities won't expect that. Another thing you might try is to replace os.system with popen2.popen3 like this: >>> import popen2 >>> out, inp, err = popen2.popen3('my command') >>> inp.close() >>> out.read() [output from my command] >>> err.read() [error from command] That might provide more hints than the exit codes... -- Magnus Lycka (It's really Lyckå), magnus@thinkware.se Thinkware AB, Sweden, www.thinkware.se I code Python ~ The shortest path from thought to working program From amapy at snafu.de Fri May 9 08:28:51 2003 From: amapy at snafu.de (amapy@snafu.de) Date: Fri May 9 03:28:55 2003 Subject: [python-win32] python and COM - in particular Visual SourceSafe Message-ID: > Hello Andreas, Hi Tony, > > I use VB at my work, and I'mjust starting to use Python. That's a good idea. > > I haven't tried accessing VSS yet- but now that you've shown me how, I > want t try it. > What does the makepy- utility do-that you mention below ? > > thanks > tony I'm not a theoretical specialist for the COM-technology, but makepy genearates the file 78CD4E0-9D54-11CF-B8EE-00608CC9A71Fx0x5x1.py under Lib\site-packages\win32com\gen_py where all constants, methods and properties of the SSAPI.DLL (the SourceSafe type library) are listed. In the pythonwin-IDE (Many thanks to Mark Hammond) autocomplete does work fine after generating this file like the MS-IDE. The expected method I need will be listed in this way: # Result is of type IVSSItem # The method GetVersion is actually a property, but must be used as a method to correctly pass the arguments def GetVersion(self, Version=defaultNamedOptArg): ret = self._oleobj_.InvokeTypes(0x18, LCID, 2, (9, 0), ((12,17),),Version) if ret is not None: ret = win32com.client.Dispatch (ret, 'GetVersion', '{2A0DE0E7-2E9F-11D0-9236-00AA00A1EB95}', UnicodeToString=0) return ret (The mail-program will give the sequence maybe a wrong format) Considere that oVSSItem is a object of type IVSSItem. I can get any version of this item like this: ThisVersion = oVSSItem.GetVersion() The problem I have is, that the method GetVersion will not appear in the object catalog of VB. Why I can see .GetVersion in the makepy-file ? regards Andi From email2et at yahoo.com Fri May 9 04:17:57 2003 From: email2et at yahoo.com (ET Planet) Date: Fri May 9 06:18:04 2003 Subject: [python-win32] Conflicts with Python In-Reply-To: Message-ID: <20030509101757.49346.qmail@web20208.mail.yahoo.com> I wrote a GUI using Tkinter and was trying to open simple applications like the Notepad program or Net Send in it. However, whenever I run it, the screen blacks out. Upon installing it on another PC, it works. Hence, I wonder if there was any conflicting file that I may have unknowingly on the troubled PC. Dudley McFadden wrote: On occasion I have similar behavior when using DDE (Dynamic Data Exchange). Either pythonwin or another application blocks until the other completes some operation. Perhaps you are simultaneously running some other program that is doing its DDE operations "impolitely." I have not taken the time to identify the root cause of my problem, but it only comes up when I am dealing with DDE. ET Planet, please post details of what exactly you are doing when you say, "did an external .exe call." Okay? --dudley _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 --------------------------------- Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20030509/10faa6e8/attachment.htm From scottprive at earthlink.net Fri May 9 09:08:24 2003 From: scottprive at earthlink.net (Scott Prive) Date: Fri May 9 08:08:34 2003 Subject: [python-win32] Conflicts with Python References: <20030509101757.49346.qmail@web20208.mail.yahoo.com> Message-ID: <027b01c31623$b334e340$0601a8c0@scottprive.com> Works on one PC but not another, and it's the same code? But the first thing I would do is examine the differences between the two systems: same Python, same Tk version, same OS version of Windows? On the computer that blacks out, any special background software like virus scanner or system security? (You might not even know what's running, if it's corporate software that hides itself from the Task Manager). What if your example code was one of the example Tk or app-running examples from the documentation? Did they work OK? Obviously I'm doing some guessing here... I can't see what might cause this, but my first suspicion based on your description is system-specific. Lastly, it might help to trim your application to the fewest number of lines to reproduce the problem. That may uncover detail, and give us something to test with. Hope this helps, -Scott ----- Original Message ----- From: ET Planet To: mcfadden@ford-consulting.com ; Python-win32@python.org Sent: Friday, May 09, 2003 6:17 AM Subject: RE: [python-win32] Conflicts with Python I wrote a GUI using Tkinter and was trying to open simple applications like the Notepad program or Net Send in it. However, whenever I run it, the screen blacks out. Upon installing it on another PC, it works. Hence, I wonder if there was any conflicting file that I may have unknowingly on the troubled PC. Dudley McFadden wrote: On occasion I have similar behavior when using DDE (Dynamic Data Exchange). Either pythonwin or another application blocks until the other completes some operation. Perhaps you are simultaneously running some other program that is doing its DDE operations "impolitely." I have not taken the time to identify the root cause of my problem, but it only comes up when I am dealing with DDE. ET Planet, please post details of what exactly you are doing when you say, "did an external .exe call." Okay? --dudley _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 ------------------------------------------------------------------------------ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. ------------------------------------------------------------------------------ _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20030509/85a8a9df/attachment.htm From lbates at syscononline.com Fri May 9 12:38:40 2003 From: lbates at syscononline.com (Larry Bates) Date: Fri May 9 12:38:52 2003 Subject: [python-win32] Re: os.system problem In-Reply-To: Message-ID: <007401c31649$734b1530$9500a8c0@larrywxp> Just thought I'd jump in here with another suggestion. Since you are working on W2K you might want to try using win32process.CreateProcess instead. I just finished a project and this seemed to work best for me. I gave me much finer control over execution of external programs. Below is a code fragment: import win32process STARTUPINFO=win32process.STARTUPINFO() STARTUPINFO.dwX=0 # X window offset STARTUPINFO.dwY=0 # Y window offset STARTUPINFO.dwXSize=800 # X size in pixels STARTUPINFO.dwYSize=600 # Y size in pixels win32process.CreateProcess(executestring, None, None, None, 0, 0, None, None, STARTUPINFO) where executestring is the full UNC path to what you wish to run. I refer you to the win32 documentation for additional information on CreateProcess. Regards, Larry -----Original Message----- From: python-win32-bounces@python.org [mailto:python-win32-bounces@python.org]On Behalf Of python-win32-request@python.org Sent: Friday, May 09, 2003 11:03 AM To: python-win32@python.org Subject: Python-win32 Digest, Vol 2, Issue 8 Send Python-win32 mailing list submissions to python-win32@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@python.org You can reach the person managing the list at python-win32-owner@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. python and COM - in particular Visual SourceSafe Automation and python (Andreas Maurer) 2. Re: os.system problem (Magnus Lyck?) 3. Re: python and COM - in particular Visual SourceSafe (amapy@snafu.de) 4. RE: Conflicts with Python (ET Planet) 5. Re: Conflicts with Python (Scott Prive) ---------------------------------------------------------------------- Message: 1 Date: Thu, 08 May 2003 22:04:13 +0200 From: Andreas Maurer Subject: [python-win32] python and COM - in particular Visual SourceSafe Automation and python To: python win32 Message-ID: <3EBAB83D.2000504@snafu.de> Content-Type: text/plain; charset=us-ascii; format=flowed Hi everybody, I've a question about a strange behavior about comparing Visual Basic and python. Don't worry ;-) I used Visual SourceSafe under python with teh SourceSafe COM-Server --> oVSS = win32com.client.Dispatch('SourceSafe'). Everything works fine. I accomplished the makepy-utility and for the VSSItem-object the GetVersion method was available. When I try the same in Visual Basic I cant't see the VSSItem.GetVersion(...) method. Why does python and win32com find this method in the right way and how does makepy work, that this important method is available under python and not under VB? I will be very appreciated for any hints to solve this mystery Andi ------------------------------ Message: 2 Date: Thu, 08 May 2003 23:43:50 +0200 From: Magnus Lyck? Subject: Re: [python-win32] os.system problem To: "Lawrence W. Leung" , python-win32@python.org Message-ID: <5.2.1.1.0.20030508233300.0260d120@www.thinkware.se> Content-Type: text/plain; charset="us-ascii"; format=flowed At 10:53 2003-05-07 -0700, Lawrence W. Leung wrote: >Hi, > >I'm trying to use os.system to execute a command in win2k with python >2.2.2 and it's not behaving as expected. Basically, the idea is I pass it >a command line that begins with a quoted path to an executable (to avoid >the problem of the space in the path) and also a quoted argument and it >fails to find the executable. But oddly enough when I unquote the >argument it seems to find the executable just fine. Doesn't the same thing happen if you run these things directly from the command line? It's my experience in Windows that I have to remove quotes that I would be using if I was in Unix. In Unix, the shell will remove the quotes before calling commands. The quotes will determine if a parameter is just one parameter, despite containing spaces etc, and single quotes will stop expansion of $ etc, but Windows don't have these things. Whatever you type at the command line will be thrown at your program, quotes and all. Unix utilities won't expect that. Another thing you might try is to replace os.system with popen2.popen3 like this: >>> import popen2 >>> out, inp, err = popen2.popen3('my command') >>> inp.close() >>> out.read() [output from my command] >>> err.read() [error from command] That might provide more hints than the exit codes... -- Magnus Lycka (It's really Lyckå), magnus@thinkware.se Thinkware AB, Sweden, www.thinkware.se I code Python ~ The shortest path from thought to working program ------------------------------ Message: 3 Date: Fri, 9 May 2003 07:28:51 GMT From: amapy@snafu.de Subject: Re: [python-win32] python and COM - in particular Visual SourceSafe To: Tony Cappellini Cc: python-win32@python.org Message-ID: > Hello Andreas, Hi Tony, > > I use VB at my work, and I'mjust starting to use Python. That's a good idea. > > I haven't tried accessing VSS yet- but now that you've shown me how, I > want t try it. > What does the makepy- utility do-that you mention below ? > > thanks > tony I'm not a theoretical specialist for the COM-technology, but makepy genearates the file 78CD4E0-9D54-11CF-B8EE-00608CC9A71Fx0x5x1.py under Lib\site-packages\win32com\gen_py where all constants, methods and properties of the SSAPI.DLL (the SourceSafe type library) are listed. In the pythonwin-IDE (Many thanks to Mark Hammond) autocomplete does work fine after generating this file like the MS-IDE. The expected method I need will be listed in this way: # Result is of type IVSSItem # The method GetVersion is actually a property, but must be used as a method to correctly pass the arguments def GetVersion(self, Version=defaultNamedOptArg): ret = self._oleobj_.InvokeTypes(0x18, LCID, 2, (9, 0), ((12,17),),Version) if ret is not None: ret = win32com.client.Dispatch (ret, 'GetVersion', '{2A0DE0E7-2E9F-11D0-9236-00AA00A1EB95}', UnicodeToString=0) return ret (The mail-program will give the sequence maybe a wrong format) Considere that oVSSItem is a object of type IVSSItem. I can get any version of this item like this: ThisVersion = oVSSItem.GetVersion() The problem I have is, that the method GetVersion will not appear in the object catalog of VB. Why I can see .GetVersion in the makepy-file ? regards Andi ------------------------------ Message: 4 Date: Fri, 9 May 2003 03:17:57 -0700 (PDT) From: ET Planet Subject: RE: [python-win32] Conflicts with Python To: mcfadden@ford-consulting.com, Python-win32@python.org Message-ID: <20030509101757.49346.qmail@web20208.mail.yahoo.com> Content-Type: text/plain; charset="us-ascii" I wrote a GUI using Tkinter and was trying to open simple applications like the Notepad program or Net Send in it. However, whenever I run it, the screen blacks out. Upon installing it on another PC, it works. Hence, I wonder if there was any conflicting file that I may have unknowingly on the troubled PC. Dudley McFadden wrote: On occasion I have similar behavior when using DDE (Dynamic Data Exchange). Either pythonwin or another application blocks until the other completes some operation. Perhaps you are simultaneously running some other program that is doing its DDE operations "impolitely." I have not taken the time to identify the root cause of my problem, but it only comes up when I am dealing with DDE. ET Planet, please post details of what exactly you are doing when you say, "did an external .exe call." Okay? --dudley _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 --------------------------------- Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20030509/10faa6e8/ attachment-0001.htm ------------------------------ Message: 5 Date: Fri, 9 May 2003 08:08:24 -0400 From: "Scott Prive" Subject: Re: [python-win32] Conflicts with Python To: "ET Planet" , , Message-ID: <027b01c31623$b334e340$0601a8c0@scottprive.com> Content-Type: text/plain; charset="iso-8859-1" Works on one PC but not another, and it's the same code? But the first thing I would do is examine the differences between the two systems: same Python, same Tk version, same OS version of Windows? On the computer that blacks out, any special background software like virus scanner or system security? (You might not even know what's running, if it's corporate software that hides itself from the Task Manager). What if your example code was one of the example Tk or app-running examples from the documentation? Did they work OK? Obviously I'm doing some guessing here... I can't see what might cause this, but my first suspicion based on your description is system-specific. Lastly, it might help to trim your application to the fewest number of lines to reproduce the problem. That may uncover detail, and give us something to test with. Hope this helps, -Scott ----- Original Message ----- From: ET Planet To: mcfadden@ford-consulting.com ; Python-win32@python.org Sent: Friday, May 09, 2003 6:17 AM Subject: RE: [python-win32] Conflicts with Python I wrote a GUI using Tkinter and was trying to open simple applications like the Notepad program or Net Send in it. However, whenever I run it, the screen blacks out. Upon installing it on another PC, it works. Hence, I wonder if there was any conflicting file that I may have unknowingly on the troubled PC. Dudley McFadden wrote: On occasion I have similar behavior when using DDE (Dynamic Data Exchange). Either pythonwin or another application blocks until the other completes some operation. Perhaps you are simultaneously running some other program that is doing its DDE operations "impolitely." I have not taken the time to identify the root cause of my problem, but it only comes up when I am dealing with DDE. ET Planet, please post details of what exactly you are doing when you say, "did an external .exe call." Okay? --dudley _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 ---------------------------------------------------------------------------- -- Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. ---------------------------------------------------------------------------- -- _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20030509/85a8a9df/ attachment-0001.htm ------------------------------ _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 End of Python-win32 Digest, Vol 2, Issue 8 ****************************************** From graham.bloice at trihedral.com Mon May 12 11:32:20 2003 From: graham.bloice at trihedral.com (Graham Bloice) Date: Mon May 12 05:32:58 2003 Subject: [python-win32] python and COM - in particular Visual SourceSafe In-Reply-To: Message-ID: > does work fine after generating this file like the MS-IDE. > The expected method I need will be listed in this way: > > # Result is of type IVSSItem > # The method GetVersion is actually a property, but must be used > as a method to > correctly pass the arguments > def GetVersion(self, Version=defaultNamedOptArg): > ret = self._oleobj_.InvokeTypes(0x18, LCID, 2, (9, 0), > ((12,17),),Version) > if ret is not None: ret = win32com.client.Dispatch > (ret, 'GetVersion', '{2A0DE0E7-2E9F-11D0-9236-00AA00A1EB95}', > UnicodeToString=0) > return ret > > (The mail-program will give the sequence maybe a wrong format) > > Considere that oVSSItem is a object of type IVSSItem. I can get any > version of this item like this: > > ThisVersion = oVSSItem.GetVersion() > > The problem I have is, that the method GetVersion will not appear in the > object catalog of VB. > > Why I can see .GetVersion in the makepy-file ? > Using OLE Viewer to view the type library for SourceSafe, shows that the IVSSItem interface has a property, Version(), that takes an argument. To allow Python to pass the argument, MakePy converts the property into a method, as indicated by the comments in the MakePy generated file. As this is a property get, the "Get" is prepended to the property name. So in VB, just look for .Version. Graham Bloice From anthony.evershed at npl.co.uk Mon May 12 10:38:03 2003 From: anthony.evershed at npl.co.uk (Anthony Evershed) Date: Mon May 12 11:43:18 2003 Subject: [python-win32] Selecting text from Microsoft Word 2000 using win32all Message-ID: <8B3E03343914D411A51000062938C7960557A6C1@golf.npl.co.uk> Hi, I was advised to seek help here for difficulties with Python's Win32 capabilities... I'm having a little trouble using Python's Win32com library to automate Microsoft Word 2000. I'm trying to highlight (block mark) a section of text from a known starting point to the end of the same line, ready for copying or deletion. For example, let's say that I want to select all the text after (and including) the word "highlight", in the line above. I can get to the start of the selection by saying: finder = wd.Selection.Find finder.Text = "highlight" finder.Execute() wd.Selection.MoveLeft() and from there I can get to the end of the line using wd.Selection.EndKey() I can see that the EndKey command allows for extra parameters - the tooltip displayed for it says (Unit=, Extend=) The "Extend=" parameter looks as if it should do the job, however the fact that it says worries me slightly, especially as wd.Selection.EndKey(1,1) wd.Selection.EndKey(Unit=1, Extend=1) wd.Selection.EndKey(1) wd.Selection.EndKey(0) all raise the exception Traceback (most recent call last): File "", line 1, in ? File "C:\Python22\lib\site-packages\win32com\gen_py\00020905-0000-0000-C000-0 00000000046x0x8x1.py", line 10178, in EndKey return self._oleobj_.InvokeTypes(0x1f9, LCID, 1, (3, 0), ((16396, 17), (16396, 17)),Unit, Extend) com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Word', 'Bad parameter', 'C:\\Program Files\\Microsoft Office\\Office\\1033\\wdmain9.chm', 36888, -2146824168), None) Secondly, is there any way to use text (or rather the ASCII equivalent) selected in this way in Python (that is, getting the text out of Word into a Python string)? If it helps, I'm using Python v2.2.2 on Windows NT 4 (though the program will be running on Windows 2000 machines as well) with win32all build 148. Many thanks, Anthony Evershed anthony.evershed@npl.co.uk ------------------------------------------------------------------- This e-mail and any attachments may contain confidential and/or privileged material; it is for the intended addressee(s) only. If you are not a named addressee, you must not use, retain or disclose such information. NPL Management Ltd cannot guarantee that the e-mail or any attachments are free from viruses. NPL Management Ltd. Registered in England and Wales. No: 2937881 Registered Office: Teddington, Middlesex, United Kingdom TW11 0LW. ------------------------------------------------------------------- From graham.bloice at trihedral.com Mon May 12 18:26:16 2003 From: graham.bloice at trihedral.com (Graham Bloice) Date: Mon May 12 12:26:54 2003 Subject: [python-win32] Selecting text from Microsoft Word 2000 usingwin32all In-Reply-To: <8B3E03343914D411A51000062938C7960557A6C1@golf.npl.co.uk> Message-ID: > For example, let's say that I want to select all the text after (and > including) the word "highlight", in the line above. I can get to the > start of the selection by saying: > > finder = wd.Selection.Find > finder.Text = "highlight" > finder.Execute() > wd.Selection.MoveLeft() > > and from there I can get to the end of the line using > > wd.Selection.EndKey() > > I can see that the EndKey command allows for extra parameters - the > tooltip displayed for it says > > (Unit=, Extend= at 0x0205B010>) > > The "Extend=" parameter looks as if it should do the job, however the > fact that it says worries me > slightly, especially as > > wd.Selection.EndKey(1,1) > wd.Selection.EndKey(Unit=1, Extend=1) > wd.Selection.EndKey(1) > wd.Selection.EndKey(0) > It would seem that you haven't yet run MakePy, hence the PyOleMissing. Run this on the Word type library, and you can then use the correct constants via win32com.client.constants in the EndKey call. The Unit parameter can have values of wdStory, wdColumn, wdLine and wdRow. The default is wdLine. The Extend parameter can have values of wdMove and wdExtend. The default is wdMove. In your case, to extend the selection to the end of the line use: wd.Selection.EndKey(Extend=win32com.client.constants.wdExtend) I don't think that you need the intervening wd.Selection.MoveLeft() either. Graham Bloice From bgailer at alum.rpi.edu Mon May 12 11:49:28 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Mon May 12 12:49:38 2003 Subject: [python-win32] Selecting text from Microsoft Word 2000 using win32all In-Reply-To: <8B3E03343914D411A51000062938C7960557A6C1@golf.npl.co.uk> Message-ID: <5.2.0.9.0.20030512100847.03018c00@66.28.54.253> At 09:38 AM 5/12/2003 +0100, Anthony Evershed wrote: >I'm having a little trouble using Python's Win32com library to automate >Microsoft Word 2000. I'm trying to highlight (block mark) a section of >text from a known starting point to the end of the same line, ready for >copying or deletion. > >For example, let's say that I want to select all the text after (and >including) the word "highlight", in the line above. I can get to the >start of the selection by saying: > >finder = wd.Selection.Find >finder.Text = "highlight" >finder.Execute() >wd.Selection.MoveLeft() > >and from there I can get to the end of the line using > >wd.Selection.EndKey() > >I can see that the EndKey command allows for extra parameters - the >tooltip displayed for it says > >(Unit=, Extend=at 0x0205B010>) > >The "Extend=" parameter looks as if it should do the job, however the >fact that it says worries me >slightly, Ignore that. >especially as > >wd.Selection.EndKey(1,1) >wd.Selection.EndKey(Unit=1, Extend=1) >wd.Selection.EndKey(1) >wd.Selection.EndKey(0) > >all raise the exception > >Traceback (most recent call last): > File "", line 1, in ? > File >"C:\Python22\lib\site-packages\win32com\gen_py\00020905-0000-0000-C000-0 >00000000046x0x8x1.py", line 10178, in EndKey > return self._oleobj_.InvokeTypes(0x1f9, LCID, 1, (3, 0), ((16396, >17), (16396, 17)),Unit, Extend) >com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Word', >'Bad parameter', 'C:\\Program Files\\Microsoft >Office\\Office\\1033\\wdmain9.chm', 36888, -2146824168), None) Where did you get the value 1 for unit? What do you expect it to do? The only acceptable values here are 5 (line), 6 (story), 9 (column) and 10 (row). WOW you say "how did he figure that out"? Easy, and you can do it too! In Word, open the Visual Basic Editor. (Tools->Macros->). From there open the Object Browser (View->). In the top comb box select word. In the 2nd combo box type endkey (enter). Selection should be boxed in the left pane and EndKey in the right. Click EndKey to see the parameter list below. Press F1 to open Help on EndKey. Notice: Unit Optional Variant. The unit by which the selection is to be moved or extended. Can be one of the following WdUnits constants: wdStory, wdColumn, wdLine, or wdRow. The default value is wdLine. Return to the object browser. Scroll on the left down to WdUnits; the named constants appear on the right.Click one and you'll see its value below. You can also use the immediate window to test things. I suggest getting O'Reilly's Learning Word Programming book. >Secondly, is there any way to use text (or rather the ASCII equivalent) >selected in this way in Python (that is, getting the text out of Word >into a Python string)? The Selection and Range objects have a Text property. You can read or set it. For example, after finder.Execute() the Selection will be the word "highlight". print wd.Selection.Text will print "using" wd.Selection.Text = 'foo' will replace "using" with "foo" [snip] Bob Gailer bgailer@alum.rpi.edu 303 442 2625 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20030512/544e4b5f/attachment.htm From bgailer at alum.rpi.edu Mon May 12 12:02:55 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Mon May 12 13:03:05 2003 Subject: [python-win32] Selecting text from Microsoft Word 2000 usingwin32all In-Reply-To: References: <8B3E03343914D411A51000062938C7960557A6C1@golf.npl.co.uk> Message-ID: <5.2.0.9.0.20030512110115.030242d0@66.28.54.253> At 05:26 PM 5/12/2003 +0100, Graham Bloice wrote: [snip] >wd.Selection.EndKey(Extend=win32com.client.constants.wdExtend) Thank you for that. I didn't know about win32com.client.constants. That will save ME a lot of effort. Bob Gailer bgailer@alum.rpi.edu 303 442 2625 From mhammond at skippinet.com.au Wed May 14 00:32:45 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue May 13 09:33:32 2003 Subject: [python-win32] Selecting text from Microsoft Word 2000usingwin32all In-Reply-To: <5.2.0.9.0.20030512110115.030242d0@66.28.54.253> Message-ID: <07a101c31954$2410bd90$530f8490@eden> > Thank you for that. I didn't know about > win32com.client.constants. That > will save ME a lot of effort. Just a reminder - win32com.client.constants will only have the constants available after the object has been created with makepy support. For example, when you start Python, win32com.client.constants will be empty. As soon as you create a Word object (assuming makepy has run), win32com.client.constants magically gets all Word constants, etc. ie, don't expect all constants to be there immediately! Mark. From charles.a.erignac at boeing.com Tue May 13 10:04:28 2003 From: charles.a.erignac at boeing.com (Erignac, Charles A) Date: Tue May 13 12:09:36 2003 Subject: [python-win32] genpy and py2exe Message-ID: <67B3A7DA6591BE439001F2736233351211E38A@xch-nw-28.nw.nos.boeing.com> I am trying to use the genpy capability from within the confines of Python program packaged by py2exe. This program and its dependent modules are packaged in a single executable zip archive. When the executable starts the support code of py2exe substitutes the default module importer, which looks for modules in the file system, with an importer that looks for modules directly in the archive. For some reason I cannot pre-package my COM wrappers. Unfortunately the py2exe is incompatible with generating wrappers on demand. Genpy will create the wrappers but the Python environment cannot load them. I have not looked deep enough yet in the importer mechanism to know whether one could add a secondary importer to look for the modules elsewhere. Suggestions are welcome. Best regards, Charles From theller at python.net Tue May 13 17:47:20 2003 From: theller at python.net (Thomas Heller) Date: Tue May 13 12:47:23 2003 Subject: [python-win32] Re: genpy and py2exe References: <67B3A7DA6591BE439001F2736233351211E38A@xch-nw-28.nw.nos.boeing.com> Message-ID: "Erignac, Charles A" writes: > I am trying to use the genpy capability from within the confines of > Python program packaged by py2exe. This program and its dependent > modules are packaged in a single executable zip archive. When the > executable starts the support code of py2exe substitutes the default > module importer, which looks for modules in the file system, with an > importer that looks for modules directly in the archive. > For some reason I cannot pre-package my COM wrappers. Unfortunately > the py2exe is incompatible with generating wrappers on demand. Genpy > will create the wrappers but the Python environment cannot load them. > I have not looked deep enough yet in the importer mechanism to know > whether one could add a secondary importer to look for the modules > elsewhere. If I understand correctly, you are running makepy (or genpy) from within the packaged program? If this is so, there are 2 problems: - where will the generated files be created, and how can you determine this directory, - how do you import these files. For the first problem, you should read the win32all code, and experiment with the exe. Foe the second problem, IIRC, you don't need a custom importer (probably). The exe-file still can import from the file system, just add the directory to sys.path. > Suggestions are welcome. > Best regards, > Charles Thomas From chrisw at nipltd.com Tue May 13 17:21:58 2003 From: chrisw at nipltd.com (Chris Withers) Date: Tue May 13 12:52:03 2003 Subject: [python-win32] right list? Message-ID: <3EC10D95.8090903@nipltd.com> Is this the right place to ask questions about automating Excel in Python via COM? If so, do I need to be a member to post? cheers, Chris From jens.jorgensen at tallan.com Tue May 13 13:14:57 2003 From: jens.jorgensen at tallan.com (Jens B. Jorgensen) Date: Tue May 13 13:15:00 2003 Subject: [python-win32] right list? In-Reply-To: <3EC10D95.8090903@nipltd.com> References: <3EC10D95.8090903@nipltd.com> Message-ID: <3EC12811.60900@tallan.com> Chris Withers wrote: > Is this the right place to ask questions about automating Excel in > Python via COM? Uh, I suppose so. The list is about issues relating python with win32. There end up being a lot of Excel automation questions here that seem to relate more to general COM or MS Office Automation than to actual Python problems but many list members (myself included) have used the win32 extensions for exactly this purpose so why don't you tell us what seems to be the problem. > If so, do I need to be a member to post? Well, this post made it so if you're not a member yet then I guess not. -- Jens B. Jorgensen jens.jorgensen@tallan.com "With a focused commitment to our clients and our people, we deliver value through customized technology solutions" From charles.a.erignac at boeing.com Tue May 13 12:16:29 2003 From: charles.a.erignac at boeing.com (Erignac, Charles A) Date: Tue May 13 14:16:41 2003 Subject: [python-win32] Re: genpy and py2exe Message-ID: <67B3A7DA6591BE439001F2736233351211E38B@xch-nw-28.nw.nos.boeing.com> I set win32com.__gen_path__ to 'C:\Temp\gen_py' through the GenPath registry key. Also made sure that the path was in sys.path. This setup works fine from python.exe. Unfortunately fron the py2exe package I still get an ImportError when loading a wrapper :(. Charles -----Original Message----- From: Thomas Heller [mailto:theller@python.net] Sent: Tuesday, May 13, 2003 9:36 AM To: python-win32@python.org Subject: [python-win32] Re: genpy and py2exe "Erignac, Charles A" writes: > I am trying to use the genpy capability from within the confines of > Python program packaged by py2exe. This program and its dependent > modules are packaged in a single executable zip archive. When the > executable starts the support code of py2exe substitutes the default > module importer, which looks for modules in the file system, with an > importer that looks for modules directly in the archive. > For some reason I cannot pre-package my COM wrappers. Unfortunately > the py2exe is incompatible with generating wrappers on demand. Genpy > will create the wrappers but the Python environment cannot load them. > I have not looked deep enough yet in the importer mechanism to know > whether one could add a secondary importer to look for the modules > elsewhere. If I understand correctly, you are running makepy (or genpy) from within the packaged program? If this is so, there are 2 problems: - where will the generated files be created, and how can you determine this directory, - how do you import these files. For the first problem, you should read the win32all code, and experiment with the exe. Foe the second problem, IIRC, you don't need a custom importer (probably). The exe-file still can import from the file system, just add the directory to sys.path. > Suggestions are welcome. > Best regards, > Charles Thomas _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 From Richard.Martin at thomson.net Tue May 13 15:19:58 2003 From: Richard.Martin at thomson.net (Martin Richard) Date: Tue May 13 15:21:52 2003 Subject: [python-win32] genpy and py2exe Message-ID: <3531F1FE12C5B4489D2014F59B4669130F7BD3@BVTNSMAIL01.am.thmulti.com> I solved the problem this way; I don't like the fact that the gen_py code is not generated at runtime. I make sure the gen_py modules are generated by first running my code. I then use this to package it: xyz_setup.py py2exe -i win32com.gen_py.* Rick -----Original Message----- From: Erignac, Charles A [mailto:charles.a.erignac@boeing.com] Sent: Tuesday, May 13, 2003 9:04 AM To: python-win32@python.org Subject: [python-win32] genpy and py2exe I am trying to use the genpy capability from within the confines of Python program packaged by py2exe. This program and its dependent modules are packaged in a single executable zip archive. When the executable starts the support code of py2exe substitutes the default module importer, which looks for modules in the file system, with an importer that looks for modules directly in the archive. For some reason I cannot pre-package my COM wrappers. Unfortunately the py2exe is incompatible with generating wrappers on demand. Genpy will create the wrappers but the Python environment cannot load them. I have not looked deep enough yet in the importer mechanism to know whether one could add a secondary importer to look for the modules elsewhere. Suggestions are welcome. Best regards, Charles _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 From thor at tordivel.no Thu May 15 13:47:52 2003 From: thor at tordivel.no (thor vollset) Date: Thu May 15 06:50:30 2003 Subject: [python-win32] What is the easiest way to execute an Excel macro fra python? Message-ID: <041001c31acf$6f993590$0600000a@TDVTV7> Is there a recommended way to do this? Is it better to run makepy and generate static binding or to use IDispatch? When supporting different versions of Excel, does this point to use IDispatch. Does anyone have any example scripts? all the best from Norway Thor Vollset ---------------------------------------------------------------------------------- TORDIVEL AS Storgata 20 0184 Oslo Norway Tel: +47 23 15 87 00 Fax: +47 23 15 87 01 E-mail: thor@tordivel.no Web: http://www.tordivel.no ---------------------------------------------------------------------------------- Scorpion Vision Software - Eliminates your weakest link ---------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20030515/080da53d/attachment.htm From jens.jorgensen at tallan.com Thu May 15 11:18:26 2003 From: jens.jorgensen at tallan.com (Jens B. Jorgensen) Date: Thu May 15 11:18:46 2003 Subject: [python-win32] What is the easiest way to execute an Excel macro fra python? In-Reply-To: <041001c31acf$6f993590$0600000a@TDVTV7> References: <041001c31acf$6f993590$0600000a@TDVTV7> Message-ID: <3EC3AFC2.7000103@tallan.com> If there are a lot of constants in the typelib then it becomes quite worthwhile to use makepy, also if there are odd functions. Other than that using IDispatch will be fine. Not sure but you should get a slight performance edge using the makepy-generated classes since the binding stuff is all there in the class def and doesn't get looked up. thor vollset wrote: > Is there a recommended way to do this? > > Is it better to run makepy and generate static binding or to > use IDispatch? > > When supporting different versions of Excel, does this point to use > IDispatch. > > Does anyone have any example scripts? > > all the best from Norway > > > Thor Vollset > ---------------------------------------------------------------------------------- > TORDIVEL AS Storgata 20 0184 Oslo Norway > Tel: +47 23 15 87 00 Fax: +47 23 15 87 01 > E-mail: thor@tordivel.no Web: > http://www.tordivel.no > ---------------------------------------------------------------------------------- > Scorpion Vision Software - Eliminates your weakest link > ---------------------------------------------------------------------------------- > > >------------------------------------------------------------------------ > >_______________________________________________ >Python-win32 mailing list >Python-win32@python.org >http://mail.python.org/mailman/listinfo/python-win32 > > -- Jens B. Jorgensen jens.jorgensen@tallan.com "With a focused commitment to our clients and our people, we deliver value through customized technology solutions" -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3108 bytes Desc: S/MIME Cryptographic Signature Url : http://mail.python.org/pipermail/python-win32/attachments/20030515/38fd8bdf/smime.bin From nugentm at myrealbox.com Thu May 15 13:47:31 2003 From: nugentm at myrealbox.com (Mike Nugent) Date: Thu May 15 13:26:44 2003 Subject: [python-win32] (no subject) Message-ID: <1053017251.a3cf64a0nugentm@myrealbox.com> I am trying to open a ADO records set against Active Directory using win32com. The problem is that a maximum of 1000 records is imposed. Microsoft docs states that setting "Page Size" to great number will allow all the records to be returned. I cannot find the Page Size setting. My tests are as folllows: PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on win32. Portions Copyright 1994-2001 Mark Hammond (mhammond@skippinet.com.au) - see 'Help/About PythonWin' for further copyright information. >>> import win32com.client >>> conn = win32com.client.Dispatch('ADODB.Connection') >>> conn.Provider='ADsDSOObject' >>> conn.Properties('Page Size') = 80000 Traceback (SyntaxError: can't assign to function call >>> conn.Properties('Page Size').Value = 80000 Traceback (most recent call last): File "", line 1, in ? File "C:\Python22\\lib\site-packages\win32com\client\dynamic.py", line 151, in __call__ return self._get_good_object_(apply(self._oleobj_.Invoke,allArgs),self._olerepr_.de faultDispatchName,None) com_error: (-2147352567, 'Exception occurred.', (0, 'ADODB.Properties', 'Item cannot be found in the collection corresponding to the requested name or ordinal.', 'C:\\WINNT\\HELP\\ADO270.CHM', 1240649, -2146825023), None) >>> conn.Open('ldap client') >>> rs, recs=conn.Execute("select ADsPath from 'LDAP://ADServer where cn = '*'") >>> rs.Properties('Page Size')=80000 Traceback (SyntaxError: can't assign to function call >>> for i in range(1,32): ... print conn.Properties(i).Name ... Pass By Ref Accessors Catalog Location Catalog Term Catalog Usage Data Source Name Read-Only Data Source Data Source Object Threading Model Maximum Row Size OLE Object Support Persistent ID Type Provider Friendly Name Provider Name OLE DB Version Provider Version SQL Support Rowset Conversions on Command User Name Password User ID Encrypt Password Integrated Security Data Source Location Extended Properties Connect Timeout Prompt Window Handle Mode Bind Flags ADSI Flag Autocommit Isolation Levels Any assistance would be appreciated. Thanks Mike From myddrin at myddrin.com Thu May 15 15:02:59 2003 From: myddrin at myddrin.com (Rob Knapp) Date: Thu May 15 14:02:06 2003 Subject: [python-win32] (no subject) In-Reply-To: <1053017251.a3cf64a0nugentm@myrealbox.com> References: <1053017251.a3cf64a0nugentm@myrealbox.com> Message-ID: <200305151801.MAA07724@www.hostingbetter.com> IIRC, it's "PageSize", not "Page Size". From thor at tordivel.no Thu May 15 21:11:43 2003 From: thor at tordivel.no (thor vollset) Date: Thu May 15 14:14:52 2003 Subject: [python-win32] Running Excel Macros from Python Message-ID: <00f001c31b0d$71221650$0600000a@TDVTV7> # this script runs the "Skrivut883" macro # when excels quits - the user are prompted to save - is there a way to avoid this prompt? from win32com.client import Dispatch myExcel = Dispatch('Excel.Application') myExcel.Visible = 1 myExcel.Workbooks.Add('c:\Termoetiketter1_2.xls') myExcel.Run('Skrivut883') myExcel.Quit() Thor Vollset ---------------------------------------------------------------------------------- TORDIVEL AS Storgata 20 0184 Oslo Norway Tel: +47 23 15 87 00 Fax: +47 23 15 87 01 E-mail: thor@tordivel.no Web: http://www.tordivel.no ---------------------------------------------------------------------------------- Scorpion Vision Software - Eliminates your weakest link ---------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20030515/15929e30/attachment.htm From bgailer at alum.rpi.edu Thu May 15 13:39:10 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Thu May 15 14:39:22 2003 Subject: [python-win32] Running Excel Macros from Python In-Reply-To: <00f001c31b0d$71221650$0600000a@TDVTV7> Message-ID: <5.2.0.9.0.20030515123827.025ea148@66.28.54.253> At 08:11 PM 5/15/2003 +0200, thor vollset wrote: ># this script runs the "Skrivut883" macro ># when excels quits - the user are prompted to save - is there a way to >avoid this prompt? > >from win32com.client import Dispatch >myExcel = Dispatch('Excel.Application') >myExcel.Visible = 1 >myExcel.Workbooks.Add('c:\Termoetiketter1_2.xls') >myExcel.Run('Skrivut883') >myExcel.Quit() The macro should either save or close the workbook. Bob Gailer bgailer@alum.rpi.edu 303 442 2625 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20030515/5fd2a683/attachment.htm From itamarst at yahoo.com Fri May 16 11:25:17 2003 From: itamarst at yahoo.com (Itamar S.-T.) Date: Fri May 16 13:25:59 2003 Subject: [python-win32] win32all and non-standard Python distribution Message-ID: <20030516172517.56159.qmail@web40812.mail.yahoo.com> I'm packaging Python by ZIPing up the c:\python22 directory and unzipping it on target machine, usually in a different directory. This works fine for the most part - except for win32all. The problem is that the win32all packages are not put straight into site-packages, but instead are added in non-package directories, and sys.path is extended (not sure how - registry?). Anyone solved this issue before? Obvious solutions would be sys.path fixups in all applications I run, messing with directory structure before ZIPing, adding some sort of site.py post-install, and getting Mark Hammond to change how win32all installs itself (can we get .h and .lib files installed too?) :) ===== Itamar Shtull-Trauring, itamar(at)shtull-trauring.org __________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. http://search.yahoo.com From theller at python.net Fri May 16 19:17:48 2003 From: theller at python.net (Thomas Heller) Date: Fri May 16 14:17:50 2003 Subject: [python-win32] Re: win32all and non-standard Python distribution References: <20030516172517.56159.qmail@web40812.mail.yahoo.com> Message-ID: "Itamar S.-T." writes: > I'm packaging Python by ZIPing up the c:\python22 > directory and unzipping it on target machine, usually > in a different directory. This works fine for the most > part - except for win32all. The problem is that the > win32all packages are not put straight into > site-packages, but instead are added in non-package > directories, and sys.path is extended (not sure how - > registry?). Are you using a recent version? AFAIK, the registry is no longer used, and all of win32all installes under lib/site-packages. Except that a handful of files is installed into the system directory, where also python22.dll is installed. > > Anyone solved this issue before? Obvious solutions > would be sys.path fixups in all applications I run, > messing with directory structure before ZIPing, adding > some sort of site.py post-install, and getting Mark > Hammond to change how win32all installs itself > (can we get .h and .lib files installed too?) :) This sounds like a good idea to me: I could make use of pywintypes.h and pywintypes.lib, do you need more? Thomas From pavlos at gaaros.com Fri May 16 20:02:34 2003 From: pavlos at gaaros.com (Pavlos Christoforou) Date: Fri May 16 14:32:08 2003 Subject: [python-win32] win32all and non-standard Python distribution In-Reply-To: <20030516172517.56159.qmail@web40812.mail.yahoo.com> Message-ID: <000001c31bd5$550dfd30$0300000a@Donkey> This is the procedure we follow to keep the python distro we ship with our application completely independent from any installed python on the target machine. 1. make a copy of the python22.dll and open it as a resource in MSVC. One of the resource strings is "2.2" which defines the subpath in the registry where this specific python dll will look for various settings. Modify this string to some other value, say "2.2_IST". 2. Lets suppose that your applications root directory is {app} and that you have unzipped the python distro in {app}\Python22\. The following registry entries will do the trick. Root: HKLM; Subkey: "SOFTWARE\Python\PythonCore\2.2_IST\PythonPath"; ValueType: string; ValueName: ""; ValueData: "{app}\ExternalModules\Python22\Lib;{app}\ExternalModules\Python22\Lib\s ite-packages;{app}\ExternalModules\Python22\DLLs" Root: HKLM; Subkey: "SOFTWARE\Python\PythonCore\2.2_IST\PythonPath\win32com"; ValueType: string; ValueName: ""; ValueData: "{app}\ExternalModules\Python22\Lib\site-packages\win32com" Root: HKLM; Subkey: "SOFTWARE\Python\PythonCore\2.2_IST\PythonPath\win32"; ValueType: string; ValueName: ""; ValueData: "{app}\ExternalModules\Python22\Lib\site-packages\win32;{app}\ExternalMo dules\Python22\Lib\site-packages\win32\lib" Root: HKLM; Subkey: "SOFTWARE\Python\PythonCore\2.2_IST\InstallPath"; ValueType: string; ValueName: ""; ValueData: "{app}\Python22" ; Flags: uninsdeletekey Pavlos Christoforou > Anyone solved this issue before? Obvious solutions > would be sys.path fixups in all applications I run, > messing with directory structure before ZIPing, adding > some sort of site.py post-install, and getting Mark > Hammond to change how win32all installs itself (can we > get .h and .lib files installed too?) :) > From Matt.Wilbert at state.ma.us Sun May 18 16:00:14 2003 From: Matt.Wilbert at state.ma.us (Wilbert, Matt (ENV)) Date: Sun May 18 15:00:20 2003 Subject: [python-win32] setting ADO page size property Message-ID: <6B4AC3A142A99446A5FEA2AE28B2F05AC048D0@ES-MSG-006.es.govt.state.ma.us> It is true that the property name is 'Page size'. Also I don't know if it works to set it as a connection property--I set it as a command property, as in this function: def getComputerList(ldapString): adoConnection = ADO.Connection() adoCommand = ADO.Command() adoRecordset = ADO.Recordset() adoConnection.Provider = "ADSDSOObject" adoConnection.Open() if adoConnection.State != ADO.constants.adStateOpen: return None else: command = "Select Name from \'%s\' where objectClass = 'Computer'" % ldapString adoCommand.ActiveConnection = adoConnection adoCommand.CommandText = command adoCommand.Properties(u'Page size').Value = 1000 adoRecordset.Open(adoCommand) try: adoRecordset.MoveLast() count = adoRecordset.RecordCount adoRecordset.MoveFirst() except: count = 0 computerList = [] for i in range(count): computername = adoRecordset.Fields.Item("Name").Value computerList.append(computername) adoRecordset.MoveNext() return computerList Hope this helps, Matt From bjarrett at garcoschools.org Mon May 19 12:22:20 2003 From: bjarrett at garcoschools.org (Brian Jarrett) Date: Mon May 19 13:22:56 2003 Subject: [python-win32] Intranet site solutions? Message-ID: <0067E36738F75E4BB04832584BAED63C0168F3@hydrogen.garcoschools.org> Hello all, I'm going to creat an intranet site this summer for the School District I work for. I've been creating some python scripts to add/remove people from groups, reset passwords, etc. in Active Directory. I'm hoping to incorporate these scripts into an intranet site that allows each school to manage student user accounts. I'm also looking to add the following features: *Helpdesk/Issue tracking/IT Project management application *Resource Calendar (for scheduling board rooms, buses, bus drivers, etc.) -- maybe integrated with exchange *knowledge base *Forums *News articles Basically, I want to make a one-stop portal that the teachers, staff, students, and administration will go to on a daily basis to ask questions, get information, etc. I would also prefer that all of these items get their authentication from Active Directory. I've downloaded Zope and will be looking at that, but first impressions are that its powerful with a steep learning curve. I've also seen RoundUp for a helpdesk app, although I'm wondering if I could get it to authenticate with AD. Any ideas in what else I could adapt to use for my intranet site would be highly appreciated. Brian Jarrett Network Administrator Garfield County School District 16 From eric at ericwalstad.com Mon May 19 18:43:49 2003 From: eric at ericwalstad.com (Eric Walstad) Date: Mon May 19 20:44:26 2003 Subject: [python-win32] py2exe runtime problem... Message-ID: <3EC97A45.4010202@ericwalstad.com> I didn't see any py2exe list, and I saw other posts on the subject in the archives, so I'm posting my question here. I have a little app consisting of 3 py files that I'm trying use with py2exe. I get a couple of "compile-time" warnings from py2exe (see below) but no errors. When I run the reuslting exe file I get a "IOError: invalid mode:" run-time error (see traceback below). If anyone can point me toward possible culptits, I'd sure appreciate it. Thanks VERY much for your time! Eric. ################## BEGIN TRACEBACK ################## C:\Documents and Settings\ewalstad\My Documents\ew\2003\pl\kiosk\plJoin\di st\Aggregator>aggregator.exe Traceback (most recent call last): File "", line 8, in ? File "imputil.pyc", line 103, in _import_hook File "", line 52, in _import_top_module File "imputil.pyc", line 216, in import_top File "imputil.pyc", line 271, in _import_one File "", line 128, in _process_result File "Serializer.pyc", line 2, in ? File "imputil.pyc", line 103, in _import_hook File "", line 52, in _import_top_module File "imputil.pyc", line 216, in import_top File "imputil.pyc", line 267, in _import_one File "", line 161, in get_code IOError: invalid mode: C:\Documents and Settings\ewalstad\My Documents\ew\2003\pl\kiosk\plJoin\di st\Aggregator> ################## END TRACEBACK ################## ################## BEGIN COMPILE INFO ################## C:\Documents and Settings\ewalstad\My Documents\ew\2003\pl\kiosk\plJoin>python s etup.py py2exe running py2exe running build running build_scripts not copying Aggregator.py (up-to-date) running install_scripts creating build\bdist.win32\winexe creating build\bdist.win32\winexe\lib creating build\bdist.win32\winexe\lib\PYTHON22 creating build\bdist.win32\winexe\lib\PYTHON22\Scripts copying build\scripts-2.2\Aggregator.py -> build\bdist.win32\winexe\lib\PYTHON22 \Scripts running install_data creating build\bdist.win32\winexe\lib\PYTHON22\db copying db\schema.sql -> build\bdist.win32\winexe\lib\PYTHON22\db copying db\sqlite.exe -> build\bdist.win32\winexe\lib\PYTHON22\db +---------------------------------------------------- | Processing script Aggregator.py with py2exe-0.3.3 +---------------------------------------------------- Copying data files not copying db\schema.sql (output up-to-date) not copying db\sqlite.exe (output up-to-date) creating build\bdist.win32\winexe\collect creating build\bdist.win32\winexe\collect\Aggregator creating build\bdist.win32\winexe\collect\Aggregator\Scripts.py2exe Searching modules needed to run 'Aggregator.py' on path: ['C:\\Documents and Settings\\ewalstad\\My Documents\\ew\\2003\\pl\\kiosk\\plJoi n\\build\\bdist.win32\\winexe\\lib\\PYTHON22\\Lib\\site-packages', '', 'C:\\Pyth on22\\lib\\site-packages\\Pythonwin', 'C:\\Python22\\lib\\site-packages\\win32', 'C:\\Python22\\lib\\site-packages\\win32\\lib', 'C:\\Python22\\lib\\site-packag es', 'C:\\PYTHON22\\DLLs', 'C:\\PYTHON22\\lib', 'C:\\PYTHON22\\lib\\lib-tk', 'C: \\PYTHON22'] force_imports = Resolving binary dependencies: C:\Python22\lib\site-packages\sqlite.dll C:\WINDOWS\System32\python22.dll C:\Python22\lib\site-packages\mx\DateTime\mxDateTime\mxDateTime.pyd C:\Python22\lib\site-packages\py2exe\run.exe C:\Python22\lib\site-packages\_sqlite.pyd C:\Python22\lib\site-packages\csv.pyd C:\PYTHON22\DLLs\_sre.pyd ext_mapping = { '_sqlite': ('_sqlite.pyd', ('.pyd', 'rb', 3)) '_sre': ('_sre.pyd', ('.pyd', 'rb', 3)) 'sqlite': ('sqlite.dll', ('', '', 5)) 'csv': ('csv.pyd', ('.pyd', 'rb', 3)) 'mx.DateTime.mxDateTime.mxDateTime': ('mxDateTime.pyd', ('.pyd', 'rb', 3)) } copying C:\Python22\lib\site-packages\py2exe\support.py -> build\bdist.win32\win exe\collect\Aggregator\Scripts.py2exe byte-compiling C:\PYTHON22\lib\pre.py to pre.pyc byte-compiling C:\Python22\lib\site-packages\sqlite\__init__.py to sqlite\__init __.pyc byte-compiling C:\PYTHON22\lib\__future__.py to __future__.pyc byte-compiling C:\PYTHON22\lib\copy_reg.py to copy_reg.pyc byte-compiling C:\PYTHON22\lib\sre_compile.py to sre_compile.pyc byte-compiling C:\PYTHON22\lib\macpath.py to macpath.pyc byte-compiling C:\PYTHON22\lib\popen2.py to popen2.pyc byte-compiling db.py to db.pyc byte-compiling C:\PYTHON22\lib\imputil.py to imputil.pyc byte-compiling C:\Python22\lib\site-packages\mx\DateTime\__init__.py to mx\DateT ime\__init__.pyc byte-compiling C:\PYTHON22\lib\shutil.py to shutil.pyc byte-compiling C:\Python22\lib\site-packages\mx\DateTime\DateTime.py to mx\DateT ime\DateTime.pyc byte-compiling C:\Python22\lib\site-packages\sqlite\main.py to sqlite\main.pyc byte-compiling C:\PYTHON22\lib\dospath.py to dospath.pyc byte-compiling C:\Python22\lib\site-packages\mx\DateTime\Parser.py to mx\DateTim e\Parser.pyc byte-compiling C:\Python22\lib\site-packages\mx\DateTime\Timezone.py to mx\DateT ime\Timezone.pyc byte-compiling C:\Python22\lib\site-packages\mx\DateTime\mxDateTime\__init__.py to mx\DateTime\mxDateTime\__init__.pyc byte-compiling C:\PYTHON22\lib\rfc822.py to rfc822.pyc byte-compiling C:\PYTHON22\lib\sre_constants.py to sre_constants.pyc byte-compiling C:\PYTHON22\lib\re.py to re.pyc byte-compiling C:\Python22\lib\site-packages\mx\DateTime\ISO.py to mx\DateTime\I SO.pyc byte-compiling Serializer.py to Serializer.pyc byte-compiling C:\Python22\lib\site-packages\mx\DateTime\ARPA.py to mx\DateTime\ ARPA.pyc byte-compiling C:\PYTHON22\lib\getopt.py to getopt.pyc byte-compiling C:\PYTHON22\lib\ntpath.py to ntpath.pyc byte-compiling C:\PYTHON22\lib\stat.py to stat.pyc byte-compiling csiSplit.py to csiSplit.pyc byte-compiling C:\PYTHON22\lib\string.py to string.pyc byte-compiling C:\PYTHON22\lib\warnings.py to warnings.pyc byte-compiling C:\PYTHON22\lib\UserDict.py to UserDict.pyc byte-compiling C:\Python22\lib\site-packages\mx\Misc\__init__.py to mx\Misc\__in it__.pyc byte-compiling C:\Python22\lib\site-packages\mx\Misc\LazyModule.py to mx\Misc\La zyModule.pyc byte-compiling C:\PYTHON22\lib\repr.py to repr.pyc byte-compiling C:\PYTHON22\lib\copy.py to copy.pyc byte-compiling C:\PYTHON22\lib\types.py to types.pyc byte-compiling C:\PYTHON22\lib\sre.py to sre.pyc byte-compiling C:\Python22\lib\site-packages\mx\__init__.py to mx\__init__.pyc byte-compiling C:\PYTHON22\lib\weakref.py to weakref.pyc byte-compiling C:\PYTHON22\lib\linecache.py to linecache.pyc byte-compiling C:\PYTHON22\lib\posixpath.py to posixpath.pyc byte-compiling C:\PYTHON22\lib\sre_parse.py to sre_parse.pyc byte-compiling C:\PYTHON22\lib\os.py to os.pyc copying Aggregator.py -> build\bdist.win32\winexe\collect\Aggregator\Scripts.py2 exe\__main__.py changing into 'build\bdist.win32\winexe\collect\Aggregator' zip -rq "C:\Documents and Settings\ewalstad\My Documents\ew\2003\pl\kiosk\plJoin \build\bdist.win32\winexe\Aggregator.zip" . creating 'C:\Documents and Settings\ewalstad\My Documents\ew\2003\pl\kiosk\plJoi n\build\bdist.win32\winexe\Aggregator.zip' and adding '.' to it changing back to 'C:\Documents and Settings\ewalstad\My Documents\ew\2003\pl\kio sk\plJoin' creating dist\Aggregator\Aggregator.exe not copying C:\Python22\lib\site-packages\sqlite.dll (output up-to-date) not copying C:\WINDOWS\System32\python22.dll (output up-to-date) not copying C:\Python22\lib\site-packages\mx\DateTime\mxDateTime\mxDateTime.pyd (output up-to-date) not copying C:\Python22\lib\site-packages\_sqlite.pyd (output up-to-date) not copying C:\Python22\lib\site-packages\csv.pyd (output up-to-date) not copying C:\PYTHON22\DLLs\_sre.pyd (output up-to-date) warning: py2exe: *************************************************************** ********** warning: py2exe: * The following modules were not found: warning: py2exe: * mxDateTime.__version__ warning: py2exe: * os.path warning: py2exe: *************************************************************** ********** removing 'build\bdist.win32\winexe\collect\Aggregator' (and everything under it) Built File dist\Aggregator\Aggregator.exe removing 'build\bdist.win32\winexe' (and everything under it) ################## END COMPILE INFO ################## From bgailer at alum.rpi.edu Mon May 19 22:10:25 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Mon May 19 23:10:34 2003 Subject: [python-win32] Configuration File In-Reply-To: <000001c31bd5$550dfd30$0300000a@Donkey> References: <20030516172517.56159.qmail@web40812.mail.yahoo.com> Message-ID: <5.2.0.9.0.20030519210123.03cf2e60@66.28.54.253> "This file has extensive comments, including how to create your own configuration based on the default." I wish for a few more words so I could really create the configuration I desire. Addressing questions including but not limited to: 1) what do <<>> mean? Why are some things in them e.g. <> and others not e.g. ProcessEnter? I do notice that things in <<>> have hyphens and are lower-case. Is that significant? 2) what other properties and methods does editor_window and editor_window.text have? 3) what use is the event parameter? How, for example, would I define a key that would swap the current line with the line above? e.g. select line, cut it, move up, paste? How could I add items to the right click menu? Bob Gailer bgailer@alum.rpi.edu 303 442 2625 From theller at python.net Tue May 20 09:09:37 2003 From: theller at python.net (Thomas Heller) Date: Tue May 20 04:09:39 2003 Subject: [python-win32] Re: py2exe runtime problem... References: <3EC97A45.4010202@ericwalstad.com> Message-ID: Eric Walstad writes: > I didn't see any py2exe list, and I saw other posts on the subject in > the archives, so I'm posting my question here. > > > I have a little app consisting of 3 py files that I'm trying use with > py2exe. I get a couple of "compile-time" warnings from py2exe (see > below) but no errors. When I run the reuslting exe file I get a > "IOError: invalid mode:" run-time error (see traceback below). > > > If anyone can point me toward possible culptits, I'd sure appreciate it. > > Thanks VERY much for your time! > > Eric. > > ################## BEGIN TRACEBACK ################## > > C:\Documents and Settings\ewalstad\My Documents\ew\2003\pl\kiosk\plJoin\di > st\Aggregator>aggregator.exe > Traceback (most recent call last): > File "", line 8, in ? > File "imputil.pyc", line 103, in _import_hook > File "", line 52, in _import_top_module > File "imputil.pyc", line 216, in import_top > File "imputil.pyc", line 271, in _import_one > File "", line 128, in _process_result > File "Serializer.pyc", line 2, in ? > File "imputil.pyc", line 103, in _import_hook > File "", line 52, in _import_top_module > File "imputil.pyc", line 216, in import_top > File "imputil.pyc", line 267, in _import_one > File "", line 161, in get_code > IOError: invalid mode: The "" above refers to the code in lib/site-packages/py2exe/support.py. Around line 161, there is this: info = _extensions_mapping.get(fqname) if info: pathname, desc = info # prepend exe_dir to filename pathname = "%s\\%s" % (sys.prefix, pathname) # Should catch IOError and convert into ImportError ?? (161) fp = open(pathname, desc[1]) dict['__file__'] = pathname return 0, imp.load_module(fqname, fp, pathname, desc), dict Can you insert some print statements before this line to see what's going wrong? I'm concerned about the comment before this line. Thomas From DDriver at covercraft.com Tue May 20 12:43:51 2003 From: DDriver at covercraft.com (Driver, David) Date: Tue May 20 12:43:58 2003 Subject: [python-win32] Problems with Event log modules Message-ID: <5B880349CA70D4119B7500D0B74C62D9010F8114@EXCHANGE> Has anyone ever ran into a situation where the command line utility dumpel includes events that are not exported by win32evtlog? Well, I am having that problem. Nothing is throwing an error, It just isn't in the result set. Any help or insight is appreciated! From nugentm at myrealbox.com Tue May 20 15:15:58 2003 From: nugentm at myrealbox.com (nugentm) Date: Tue May 20 14:21:22 2003 Subject: [python-win32] Re: setting ADO page size property References: <6B4AC3A142A99446A5FEA2AE28B2F05AC048D0@ES-MSG-006.es.govt.state.ma.us> Message-ID: <001b01c31efb$dfa73e10$b51a350a@ffci.com> Thanks for the assistance. I cannot figure out how to use ADO. So, instead I used: import win32com.client adoRecordset=win32com.client.Dispatch('ADODB.Recordset') adoConnection=win32com.client.Dispatch('ADODB.Connection') adoCommand=win32com.client.Dispatch('ADODB.Command') It works great. Thanks again for the help. Mike ----- Original Message ----- From: "Wilbert, Matt (ENV)" To: Cc: Sent: Sunday, May 18, 2003 3:00 PM Subject: setting ADO page size property It is true that the property name is 'Page size'. Also I don't know if it works to set it as a connection property--I set it as a command property, as in this function: def getComputerList(ldapString): adoConnection = ADO.Connection() adoCommand = ADO.Command() adoRecordset = ADO.Recordset() adoConnection.Provider = "ADSDSOObject" adoConnection.Open() if adoConnection.State != ADO.constants.adStateOpen: return None else: command = "Select Name from \'%s\' where objectClass = 'Computer'" % ldapString adoCommand.ActiveConnection = adoConnection adoCommand.CommandText = command adoCommand.Properties(u'Page size').Value = 1000 adoRecordset.Open(adoCommand) try: adoRecordset.MoveLast() count = adoRecordset.RecordCount adoRecordset.MoveFirst() except: count = 0 computerList = [] for i in range(count): computername = adoRecordset.Fields.Item("Name").Value computerList.append(computername) adoRecordset.MoveNext() return computerList Hope this helps, Matt From eric at ericwalstad.com Tue May 20 12:31:35 2003 From: eric at ericwalstad.com (Eric Walstad) Date: Tue May 20 14:31:18 2003 Subject: [python-win32] Re: py2exe runtime problem... In-Reply-To: References: <3EC97A45.4010202@ericwalstad.com> Message-ID: <3ECA7487.3050004@ericwalstad.com> Hi Thomas, Thanks for the reply and help with debugging the problem. See below for details. Thomas Heller wrote: > Eric Walstad writes: > > >>I didn't see any py2exe list, and I saw other posts on the subject in >>the archives, so I'm posting my question here. >> >> >>I have a little app consisting of 3 py files that I'm trying use with >>py2exe. I get a couple of "compile-time" warnings from py2exe (see >>below) but no errors. When I run the reuslting exe file I get a >>"IOError: invalid mode:" run-time error (see traceback below). >> >> >>If anyone can point me toward possible culptits, I'd sure appreciate it. >> >>Thanks VERY much for your time! >> >>Eric. >> >>################## BEGIN TRACEBACK ################## >> >>C:\Documents and Settings\ewalstad\My Documents\ew\2003\pl\kiosk\plJoin\di >>st\Aggregator>aggregator.exe >>Traceback (most recent call last): >> File "", line 8, in ? >> File "imputil.pyc", line 103, in _import_hook >> File "", line 52, in _import_top_module >> File "imputil.pyc", line 216, in import_top >> File "imputil.pyc", line 271, in _import_one >> File "", line 128, in _process_result >> File "Serializer.pyc", line 2, in ? >> File "imputil.pyc", line 103, in _import_hook >> File "", line 52, in _import_top_module >> File "imputil.pyc", line 216, in import_top >> File "imputil.pyc", line 267, in _import_one >> File "", line 161, in get_code >>IOError: invalid mode: > > > The "" above refers to the code in > lib/site-packages/py2exe/support.py. Around line 161, there is this: > > info = _extensions_mapping.get(fqname) > if info: > pathname, desc = info > # prepend exe_dir to filename > pathname = "%s\\%s" % (sys.prefix, pathname) > # Should catch IOError and convert into ImportError ?? > (161) fp = open(pathname, desc[1]) > dict['__file__'] = pathname > return 0, imp.load_module(fqname, fp, pathname, desc), dict > > Can you insert some print statements before this line to see what's > going wrong? I'm concerned about the comment before this line. OK, here's how I changed the support.py file: info = _extensions_mapping.get(fqname) print "*******************************************************" print "DEBUG-> parent, modname, fqname, get_code, _pyc_suffix:", parent, modname, fqname, get_code, _pyc_suffix print "DEBUG-> info:", info if info: pathname, desc = info print "DEBUG-> pathname, desc:", pathname, desc # prepend exe_dir to filename pathname = "%s\\%s" % (sys.prefix, pathname) print "DEBUG-> sys.prefix\pathname:", pathname # Should catch IOError and convert into ImportError ?? print "DEBUG-> desc[1]:", desc[1] print "DEBUG-> *** ABOUT TO OPEN FILE..." fp = open(pathname, desc[1]) print "DEBUG-> *** FILE OPENED, fp:", fp dict['__file__'] = pathname imp_loadmodule = imp.load_module(fqname, fp, pathname, desc) print "DEBUG-> imp_loadmodule:", imp_loadmodule print "DEBUG-> dict:", dict return 0, imp_loadmodule, dict And here's the output and traceback. I looked for "_extensions_mapping," as it appears to be when the _pyc_suffix info is lost, but couldn't find it in my Python22 dir. C:\Documents and Settings\ewalstad\My Documents\ew\2003\pl\kiosk\plJoin\dist\Aggregator>aggregator.exe ******************************************************* DEBUG-> parent, modname, fqname, get_code, _pyc_suffix: None csiSplit csiSplit ('.pyc', 'rb', 2) DEBUG-> info: None ******************************************************* DEBUG-> parent, modname, fqname, get_code, _pyc_suffix: None os os ('.pyc', 'rb', 2) DEBUG-> info: None ******************************************************* DEBUG-> parent, modname, fqname, get_code, _pyc_suffix: None ntpath ntpath ('.pyc', 'rb', 2) DEBUG-> info: None ******************************************************* DEBUG-> parent, modname, fqname, get_code, _pyc_suffix: None stat stat ('.pyc', 'rb', 2) DEBUG-> info: None ******************************************************* DEBUG-> parent, modname, fqname, get_code, _pyc_suffix: None UserDict UserDict ('.pyc', 'rb', 2) DEBUG-> info: None ******************************************************* DEBUG-> parent, modname, fqname, get_code, _pyc_suffix: None copy_reg copy_reg ('.pyc', 'rb', 2) DEBUG-> info: None ******************************************************* DEBUG-> parent, modname, fqname, get_code, _pyc_suffix: None types types ('.pyc', 'rb', 2) DEBUG-> info: None ******************************************************* DEBUG-> parent, modname, fqname, get_code, _pyc_suffix: None __future__ __future__ ('.pyc', 'rb', 2) DEBUG-> info: None ******************************************************* DEBUG-> parent, modname, fqname, get_code, _pyc_suffix: None shutil shutil ('.pyc', 'rb', 2) DEBUG-> info: None ******************************************************* DEBUG-> parent, modname, fqname, get_code, _pyc_suffix: None csv csv ('.pyc', 'rb', 2) DEBUG-> info: ('csv.pyd', ('.pyd', 'rb', 3)) DEBUG-> pathname, desc: csv.pyd ('.pyd', 'rb', 3) DEBUG-> sys.prefix\pathname: C:\Documents and Settings\ewalstad\My Documents\ew\2003\pl\kiosk\plJoin\dist\Aggregator\csv.pyd DEBUG-> desc[1]: rb DEBUG-> *** ABOUT TO OPEN FILE... DEBUG-> *** FILE OPENED, fp: DEBUG-> imp_loadmodule: DEBUG-> dict: {'__file__': 'C:\\Documents and Settings\\ewalstad\\My Documents\\ew\\2003\\pl\\kiosk\\plJoin\\dist\\Aggregator\\csv.pyd'} ******************************************************* DEBUG-> parent, modname, fqname, get_code, _pyc_suffix: None Serializer Serializer ('.pyc', 'rb', 2) DEBUG-> info: None ******************************************************* DEBUG-> parent, modname, fqname, get_code, _pyc_suffix: None sqlite sqlite ('.pyc', 'rb', 2) DEBUG-> info: ('sqlite.dll', ('', '', 5)) DEBUG-> pathname, desc: sqlite.dll ('', '', 5) DEBUG-> sys.prefix\pathname: C:\Documents and Settings\ewalstad\My Documents\ew\2003\pl\kiosk\plJoin\dist\Aggregator\sqlite.dll DEBUG-> desc[1]: DEBUG-> *** ABOUT TO OPEN FILE... Traceback (most recent call last): File "", line 8, in ? File "imputil.pyc", line 103, in _import_hook File "", line 52, in _import_top_module File "imputil.pyc", line 216, in import_top File "imputil.pyc", line 271, in _import_one File "", line 128, in _process_result File "Serializer.pyc", line 4, in ? File "imputil.pyc", line 103, in _import_hook File "", line 52, in _import_top_module File "imputil.pyc", line 216, in import_top File "imputil.pyc", line 267, in _import_one File "", line 168, in get_code IOError: invalid mode: From theller at python.net Tue May 20 19:59:35 2003 From: theller at python.net (Thomas Heller) Date: Tue May 20 14:59:36 2003 Subject: [python-win32] Re: py2exe runtime problem... In-Reply-To: <3ECA7487.3050004@ericwalstad.com> References: <3EC97A45.4010202@ericwalstad.com> <3ECA7487.3050004@ericwalstad.com> Message-ID: Eric Walstad writes: > Hi Thomas, > Thanks for the reply and help with debugging the problem. See below > for details. Before I further look into this, two questions: - Is the sqlite.dll which causes the problem a Python extension module, or is it a DLL needed by a Python module? - Did you try building with py2exe version 0.3.4? Thomas From Andrew.MacIntyre at aba.gov.au Thu May 22 16:49:20 2003 From: Andrew.MacIntyre at aba.gov.au (Andrew MacIntyre) Date: Thu May 22 01:53:50 2003 Subject: [python-win32] win32com.client.CastTo() & references to interfaces in other libr aries Message-ID: I'm working with a package (ESRI ArcGIS) that supports a number of ActiveX controls. Various methods of the generated interface classes are noted in comments to return references to objects not defined in the control type library, but which are defined in one of several "support" type libraries. Looking at the makepy generated files for the support libraries, I find that many interfaces don't have class definitions, but do have _vtables_dispatch_ = ? _vtables_ = [ ] sections, where the "?" is usually either 0 or 1. Other interfaces have both the class definition and the "_vtables..." definitions. What is the significance of this? How can I access the members of an interface which has no class definition? After coming across a reference by MarkH to CastTo() in the list archives, and not finding any docs, I perused the source. Unfortunately, the current version's comments note that support for interfaces in other type libraries doesn't yet exist :-(. If its not obvious, I'm new to COM programming in general, and Pythonwin (but not Python) in particular. If anyone has some recommendations for books or online resources, especially non-trivial application sources that I can look over for enlightment, that would be most appreciated. Regards, Andrew. ----------------------------------------------------------------------- Andrew MacIntyre \ E-mail: andrew.macintyre@aba.gov.au Planning & Licensing Branch \ Tel: +61 2 6256 2812 Australian Broadcasting Authority \ Fax: +61 2 6253 3277 -> "These thoughts are mine alone!" <---------------------------------- From eric at ericwalstad.com Thu May 22 10:12:49 2003 From: eric at ericwalstad.com (Eric Walstad) Date: Thu May 22 12:13:23 2003 Subject: [python-win32] Re: py2exe runtime problem... In-Reply-To: References: <3EC97A45.4010202@ericwalstad.com> <3ECA7487.3050004@ericwalstad.com> Message-ID: <3ECCF701.2010603@ericwalstad.com> Hi Thomas, Thomas Heller wrote: > Before I further look into this, two questions: > - Is the sqlite.dll which causes the problem a Python extension module, > or is it a DLL needed by a Python module? sqlite.dll is used by the Python module pysqlite (version 0.4.1, if it matters). > - Did you try building with py2exe version 0.3.4? Yes, I just tried building with version 0.3.4 and I get another "IOError: invalid mode:" The trace back has changed a bit because I changed the structure of my code, but it appears to be failing at the same point. Traceback is below. Any other ideas? Thanks a million. Eric. Traceback (most recent call last): File "", line 9, in ? File "imputil.pyc", line 103, in _import_hook File "", line 52, in _import_top_module File "imputil.pyc", line 216, in import_top File "imputil.pyc", line 271, in _import_one File "", line 128, in _process_result File "Aggregator.pyc", line 8, in ? Aggregator.py File "imputil.pyc", line 103, in _import_hook File "", line 52, in _import_top_module File "imputil.pyc", line 216, in import_top File "imputil.pyc", line 271, in _import_one File "", line 128, in _process_result File "Serializer.pyc", line 4, in ? Ns File "imputil.pyc", line 103, in _import_hook File "", line 52, in _import_top_module File "imputil.pyc", line 216, in import_top File "imputil.pyc", line 267, in _import_one File "", line 161, in get_code IOError: invalid mode: From eric at ericwalstad.com Thu May 22 11:08:46 2003 From: eric at ericwalstad.com (Eric Walstad) Date: Thu May 22 13:11:45 2003 Subject: [python-win32] Re: py2exe runtime problem... In-Reply-To: <3ECCF9CC.9DE07E10@noaa.gov> References: <3EC97A45.4010202@ericwalstad.com> <3ECA7487.3050004@ericwalstad.com> <3ECCF701.2010603@ericwalstad.com> <3ECCF9CC.9DE07E10@noaa.gov> Message-ID: <3ECD041E.3090008@ericwalstad.com> Hi Jim, A bit of warning, I only started using sqlite, pysqlite and py2exe about a week ago. With that in mind... Jim Vickroy wrote: > I have pysqlite installed on my win32 system and there is no sqlite.dll; sqlite.dll is in my sqlite installation. It's my (possibly flawed) assumption that pysqlite links to the sqlite.dll library. > there is a _sqlite.pyd file; is that what you are calling sqlite.dll? No. I followed the pysqlite install instructions: As suggested in the install docs referenced above, I happen to have sqlite.dll in: site-packages and site-packages\pysqlite-0.4.1\build\lib.win32-2.2 > It is > my understanding that there is no need to have a separate sqlite.dll as that > is implicitly part of the win32 installation. I'm not clear on what you mean by "a separate sqlite.dll" here. Separate from what? I reread the installation docs with the fear that I might have botched something there, but it appears I've done it correctly. Thanks for your help, Eric. From craig.taverner at comopt.com Thu May 22 20:33:35 2003 From: craig.taverner at comopt.com (Craig Taverner) Date: Thu May 22 13:32:05 2003 Subject: [python-win32] RE: Python-win32 Digest, Vol 2, Issue 19 Message-ID: <5D0355F204917248B054EDB0D57BD9E42AB9D1@oden.comopt.com> Hi Andrew, I'm sorry I don't have a good answer for you, but I'm replying anyway because I'm also trying to use pythoncom to access the ESRI ArcObject libraries. I was fortunate enough to have a chance to discuss python access to ArcObjects with one of their key developers, Bill Moreland, who has been involved in building the next vrsion of Model Builder for ArcGIS 9.0, and they've decided to make Python the primary scripting language to replace avenue (ModulBuilder will export to python, vbscript and jscript, but they are viewing python as the best choice). He told me how because python can only access IDispatch interfaces (unless the pythoncom has native support for the interfaces, which it does not for ArcObjects), a large part of ArcObjects is not available to python normally. They have written a generic interface system of some kind to allow python, vbscript and jscript to access all these additional COM classes anyway, but with low performance. This is not really available to us except with ArcGIS 9.0, and I think also only for ModelBuilder for scripting geoprocessing. Personally I'm curious to know how difficult it would be to make the ESRI library a natively supported COM library for python. Perhaps it is just a matter of writing a wrapper C++ library that can plug into python. I'm a complete newbie to python myself, and have only chosen it because of the 'advocacy', so I do not know how to do this, or if it would be a trivial thing (eg. Have a script that reads the esriCore.olb file and auto-generates the C++ wrappers for us), or if it's tons of difficult coding. I've any of the pythonwin masters have an answer here, that would be great! I'm just getting into this, learning COM, learning ArcObjects and learning python. A triple steep learning curve ;-) Since you are working with python access to ArcObjects, and I'm trying to get into that, I think it would be nice if we kept in touch, and so we could help each other out with technical issues? Right now I'm writing a python COM server to be called from a VB application that has embedded esriCore.MapControl. The only problems I'm having so far as that the python COM server needs to be multithreaded because the VB thread cannot be blocked by long calculations, and I'm having a little trouble figuring out all the subtleties of COM/threading. If you have experience here, that would be great. Cheers, Craig > I'm working with a package (ESRI ArcGIS) that supports a number of > ActiveX controls. Various methods of the generated interface classes > are noted in comments to return references to objects not defined > in the control type library, but which are defined in one of several > "support" type libraries. > > Looking at the makepy generated files for the support libraries, I > find that many interfaces don't have class definitions, but do have > > _vtables_dispatch_ = ? > _vtables_ = [ ] > > sections, where the "?" is usually either 0 or 1. Other interfaces > have both the class definition and the "_vtables..." definitions. > > What is the significance of this? How can I access the members of > an interface which has no class definition? > > After coming across a reference by MarkH to CastTo() in the list > archives, and not finding any docs, I perused the source. > > Unfortunately, the current version's comments note that support for > interfaces in other type libraries doesn't yet exist :-(. > > If its not obvious, I'm new to COM programming in general, and > Pythonwin (but not Python) in particular. If anyone has some > recommendations for books or online resources, especially > non-trivial application sources that I can look over for > enlightment, that would be most appreciated. From eric at ericwalstad.com Thu May 22 11:57:06 2003 From: eric at ericwalstad.com (Eric Walstad) Date: Thu May 22 13:57:19 2003 Subject: [python-win32] Re: py2exe runtime problem...(SOLVED) In-Reply-To: <3ECD083B.531CDA24@noaa.gov> References: <3EC97A45.4010202@ericwalstad.com> <3ECA7487.3050004@ericwalstad.com> <3ECCF701.2010603@ericwalstad.com> <3ECCF9CC.9DE07E10@noaa.gov> <3ECD041E.3090008@ericwalstad.com> <3ECD083B.531CDA24@noaa.gov> Message-ID: <3ECD0F72.4040601@ericwalstad.com> Hi Jim, Jim Vickroy wrote: > I have been using pysqlite for some time; I always install it using the Windows binary installer > provided with the distribution. It never installs a file called sqlite.dll anywhere on my system. > At least when installed in this manner, Gerhard has said there is no need for a sqlite.dll (its > built into the distribution). Hmm, perhaps this is part of the problem then... Yes. I had installed sqlite in my site-packages directory. That was my mistake because, after following your install procedure below, pysqlite installs itself in site-packages/sqlite. I'm not clear on exactly where the name conflict was happening, but it's gone now. Yippee! IMO, it seems a bit odd to stick pysqlite in a dir named sqlite. > I just looked at the link you mentioned, and I guess you built the installation on your system so > that is why you needed sqlite.dll. I may be wrong but I think that once you build the pyd file, > sqlite.dll is no longer needed in order to use pysqlite. If I had a sqlite.dll on my system, I > would (temporarily) rename it and see if anything broke, but I don't have one to play with. Hehe. That's exactly what I did after I read your first email. Actually, I zipped up the whole sqlite installation folder, removed all the copies of sqlite.dll and then tried it... and it failed on: import sqlite Which resulted with something like "No module sqlite" > Anyway > ... > > ... that's why I'm confused. I was too! Thanks for your brain cycles and for steering me in the right direction! ;^) Eric. PS, off list, please tell me where you keep your sqlite installation (I'm guessing you still use the sqlite command line tool for admin stuff). From Andrew.MacIntyre at aba.gov.au Fri May 23 13:28:46 2003 From: Andrew.MacIntyre at aba.gov.au (Andrew MacIntyre) Date: Thu May 22 22:33:13 2003 Subject: [python-win32] RE: Python-win32 Digest, Vol 2, Issue 19 Message-ID: > From: Craig Taverner > Sent: Friday, 23 May 2003 3:34 AM > > I'm sorry I don't have a good answer for you, but I'm replying anyway > because I'm also trying to use pythoncom to access the ESRI ArcObject > libraries. Always good to have company! Thanks for taking the time to reply. > I was fortunate enough to have a chance to discuss python > access to ArcObjects with one of their key developers, Bill Moreland, > who has been involved in building the next vrsion of Model Builder for > ArcGIS 9.0, and they've decided to make Python the primary scripting > language to replace avenue (ModulBuilder will export to > python, vbscript > and jscript, but they are viewing python as the best choice). Excellent!! > He told me > how because python can only access IDispatch interfaces (unless the > pythoncom has native support for the interfaces, which it does not for > ArcObjects), a large part of ArcObjects is not available to python > normally. They have written a generic interface system of some kind to > allow python, vbscript and jscript to access all these additional COM > classes anyway, but with low performance. This is not really available > to us except with ArcGIS 9.0, and I think also only for > ModelBuilder for scripting geoprocessing. :-( I had inferred that Pythoncom's early binding would be sufficient to deal with the documented IDispatch restriction, but Bill's comments would seem to make that unlikely... I came across 1 reference to vtables (C++) based interfaces in the Pythoncom help file, albeit in relation to COM servers, which gives me faint hope this is still feasible. Lots of reading & code inspection still to do... > Personally I'm curious to know how difficult it would be to make the > ESRI library a natively supported COM library for python. > Perhaps it is just a matter of writing a wrapper C++ library that can > plug into python. I'm a complete newbie to python myself, and have only > chosen it because of the 'advocacy', so I do not know how to do this, > or if it would be a trivial thing (eg. Have a script that reads the > esriCore.olb file and auto-generates the C++ wrappers for us), or if > it's tons of difficult coding. While comfortable with C, C++ is something I've never gotten into. I was hoping I could use Python instead of VB for my Arc based app. > I've any of the pythonwin masters have an answer here, that would be > great! > > I'm just getting into this, learning COM, learning ArcObjects and > learning python. A triple steep learning curve ;-) I've been using Python and Arc/Info (the workstation version) for a few years, and have picked up some ArcObjects familiarity through MXD document macros in VBA, so my learning curve isn't quite as steep ... > Since you are working with python access to ArcObjects, and I'm trying > to get into that, I think it would be nice if we kept in touch, and so > we could help each other out with technical issues? Good idea. > Right now I'm writing a python COM server to be called from a VB > application that has embedded esriCore.MapControl. The only > problems I'm > having so far as that the python COM server needs to be multithreaded > because the VB thread cannot be blocked by long calculations, and I'm > having a little trouble figuring out all the subtleties of > COM/threading. If you have experience here, that would be great. Sorry :-( I have little experience with threading full stop. Regards, Andrew. ----------------------------------------------------------------------- Andrew MacIntyre \ E-mail: andrew.macintyre@aba.gov.au Planning & Licensing Branch \ Tel: +61 2 6256 2812 Australian Broadcasting Authority \ Fax: +61 2 6253 3277 -> "These thoughts are mine alone!" <---------------------------------- From craig.taverner at comopt.com Fri May 23 10:49:46 2003 From: craig.taverner at comopt.com (Craig Taverner) Date: Fri May 23 03:48:15 2003 Subject: [python-win32] RE: Can we add 'native COM support' to a 3rd party DLL/OLB Message-ID: <5D0355F204917248B054EDB0D57BD9E42AB9D2@oden.comopt.com> > :-( I had inferred that Pythoncom's early binding would be sufficient > to deal with the documented IDispatch restriction, but Bill's comments > would seem to make that unlikely... > > I came across 1 reference to vtables (C++) based interfaces in the > Pythoncom help file, albeit in relation to COM servers, which gives > me faint hope this is still feasible. Lots of reading & code inspection > still to do... Let me know what you find. I also still have hope. I think the system the ESRI developers worked on was generic to three languages. We're only interested in one, and python is supposed to be easy to extend, so I think a relatively simple solution must be possible. > While comfortable with C, C++ is something I've never gotten into. I > was hoping I could use Python instead of VB for my Arc based app. That is exactly my hope. Also we do a lot of java programming server side and are using Jython for scripting in that, so we also want to keep python for scripting in the ArcObjects based clients. > > I've any of the pythonwin masters have an answer here, that would be > > great! I've changed the subject line to reflect the primary question to the python-win32 list, in case they have an answer for us. > I've been using Python and Arc/Info (the workstation version) for a > few years, and have picked up some ArcObjects familiarity through > MXD document macros in VBA, so my learning curve isn't quite as steep > ... I'm new to python, COM and ArcGIS, but experienced with threads, CORBA, Java and some C++, so we're approaching this problem from different directions. Can only help ;-) > Sorry :-( I have little experience with threading full stop. My only strength ;-) (at least I'm experienced with posix threads, omnithreads, java threads, and now trying out python and win32 threads). From Andrew.MacIntyre at aba.gov.au Fri May 23 19:19:47 2003 From: Andrew.MacIntyre at aba.gov.au (Andrew MacIntyre) Date: Fri May 23 04:23:41 2003 Subject: [python-win32] RE: Can we add 'native COM support' to a 3rd party DLL/OLB Message-ID: > From: Craig Taverner > Sent: Friday, 23 May 2003 5:50 PM {...} > > I came across 1 reference to vtables (C++) based interfaces in the > > Pythoncom help file, albeit in relation to COM servers, which gives > > me faint hope this is still feasible. Lots of reading & code > inspection > > still to do... > > Let me know what you find. I also still have hope. I think the system > the ESRI developers worked on was generic to three languages. > We're only > interested in one, and python is supposed to be easy to extend, so I > think a relatively simple solution must be possible. The Pythonwin docs refer to creating native interfaces via SWIG, and the Pythonwin CVS contains a tweaked version of SWIG 1.1 for creating the MAPI interfaces. Exactly what the mechanics of doing this aren't yet clear to me, but I'm guessing that there must be a reasonable way to convert the type library definitions to SWIG .i files. I'm further hampered by not having access to MSVC (I've been using MinGW for the extensions I've done to date, including an Arc ODE extension set). ----------------------------------------------------------------------- Andrew MacIntyre \ E-mail: andrew.macintyre@aba.gov.au Planning & Licensing Branch \ Tel: +61 2 6256 2812 Australian Broadcasting Authority \ Fax: +61 2 6253 3277 -> "These thoughts are mine alone!" <---------------------------------- From niki at vintech.bg Fri May 23 12:25:35 2003 From: niki at vintech.bg (Niki Spahiev) Date: Fri May 23 04:27:15 2003 Subject: [python-win32] RE: Python-win32 Digest, Vol 2, Issue 19 In-Reply-To: References: Message-ID: <3ECDDAFF.9080204@vintech.bg> Andrew MacIntyre wrote: >>He told me >>how because python can only access IDispatch interfaces (unless the >>pythoncom has native support for the interfaces, which it does not for >>ArcObjects), a large part of ArcObjects is not available to python >>normally. They have written a generic interface system of some kind to >>allow python, vbscript and jscript to access all these additional COM >>classes anyway, but with low performance. This is not really available >>to us except with ArcGIS 9.0, and I think also only for >>ModelBuilder for scripting geoprocessing. > > > :-( I had inferred that Pythoncom's early binding would be sufficient > to deal with the documented IDispatch restriction, but Bill's comments > would seem to make that unlikely... > > I came across 1 reference to vtables (C++) based interfaces in the > Pythoncom help file, albeit in relation to COM servers, which gives > me faint hope this is still feasible. Lots of reading & code inspection > still to do... Also check ctypes project for vtables based COM. HTH Niki Spahiev From theller at python.net Fri May 23 09:44:44 2003 From: theller at python.net (Thomas Heller) Date: Fri May 23 04:44:46 2003 Subject: [python-win32] Re: Can we add 'native COM support' to a 3rd party DLL/OLB References: <5D0355F204917248B054EDB0D57BD9E42AB9D2@oden.comopt.com> Message-ID: > > :-( I had inferred that Pythoncom's early binding would be sufficient > > to deal with the documented IDispatch restriction, but Bill's comments > > would seem to make that unlikely... > > > > I came across 1 reference to vtables (C++) based interfaces in the > > Pythoncom help file, albeit in relation to COM servers, which gives > > me faint hope this is still feasible. Lots of reading & code > > > inspection still to do... > > Let me know what you find. I also still have hope. I think the system > the ESRI developers worked on was generic to three languages. We're only > interested in one, and python is supposed to be easy to extend, so I > think a relatively simple solution must be possible. > I have not really followed the discussion, but ctypes has support for vtable based interfaces. I'm currently writing some docs, you may want to check it out: http://starship.python.net/crew/theller/ctypes/ http://starship.python.net/crew/theller/ctypes/com.html http://starship.python.net/crew/theller/ctypes/sum_sample.html > > While comfortable with C, C++ is something I've never gotten into. I > > was hoping I could use Python instead of VB for my Arc based app. To use ctypes beyond very basic use, you certainly need C knowledge. Thomas From craig.taverner at comopt.com Fri May 23 15:45:34 2003 From: craig.taverner at comopt.com (Craig Taverner) Date: Fri May 23 08:43:32 2003 Subject: [python-win32] Re: Can we add 'native COM support' to a 3rd party DLL/OLB Message-ID: <5D0355F204917248B054EDB0D57BD9E42AB9D4@oden.comopt.com> > I have not really followed the discussion, but ctypes has support > for vtable based interfaces. I'm currently writing some docs, you may > want to check it out: > > http://starship.python.net/crew/theller/ctypes/ > http://starship.python.net/crew/theller/ctypes/com.html > http://starship.python.net/crew/theller/ctypes/sum_sample.html > > > > While comfortable with C, C++ is something I've never gotten into. I > > > was hoping I could use Python instead of VB for my Arc based app. > > To use ctypes beyond very basic use, you certainly need C knowledge. Thanks Thomas, A quick read of the com.html and sum_sample.html is very interesting. I'm currently having trouble sending events from pythoncom servers to VB clients. Do you think the ctypes module will work better for me in this regard. The only reference to events that I found in your docs was the ctypes.com.connectionpoints module, which you say is for receiving events. Actually my problem involves a design that I'm sure is not uncommon, and I expect either PythonCOM or ctypes can solve it, but I've just not figured out how. If you have any advice, I'd love to hear it. The problem is I have a VB client (so single threaded apartment), and some multithreaded python code that does a bunch of calculations, some of which are time consuming. I want to glue the two together with COM such that: - VB CoCreates a python COM object which it calls to start the calculation - python creates a second thread to do the calculation, so the 'StartCalcultion' is non-blocking. - python thread signals the VB when it's finished (I've tried a callback VB COM object, which sort of works, and then crashes after # calls, but would probably prefer to use windows messages or some kind of events). Having just read the threads chapter of 'Inside COM', I'm half confident I know what kind of threading models to use, but my first attempt with PythonCOM generated OLE errors on the 'CoMarshalInterThreadInterfaceInStream' call to pass the callback VB object to the new thread. Everything I've read seemed to indicate that I needed that call, but things work better without it. However, if I knew how to work events, I would not have to worry about passing VB COM objects between threads. I've only found how to handle events in python, not how to fire them. Any ideas? Thanks, Craig From corydodt at yahoo.com Fri May 23 09:18:01 2003 From: corydodt at yahoo.com (Cory Dodt) Date: Fri May 23 11:18:05 2003 Subject: [python-win32] List references to a COM server, locks on a file Message-ID: <20030523151801.97142.qmail@web10002.mail.yahoo.com> I have the following problem. I wrote a COM server that is launched by a .dot file, a Word template. The sequence of events is: Word > launches all .dot files in C:\PF\MSO\startup > launches lexshell.dot > invokes methods on my COM server, "Lexicon.Python" > launches process lxaddin.exe When installing an upgrade version, I want to list for the user all the applications that need to be shut down to continue, rather than punch the user in the face with a forced reboot. In short, I need to list all the processes that are keeping either lexshell.dot open or lxaddin.exe running. I know that both Word and Outlook can make this happen; there may be others. For lxaddin, my thought was to invoking a COM method that lists all the processes with references to lxaddin. So I need to know the magic to make a COM server list all of its own open references. For lexshell.dot, I just want to know who has the file locked open. When I'm done, I will display a list of the processes. Any suggestions for either of these 2 problems? __________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. http://search.yahoo.com From theller at python.net Fri May 23 18:25:14 2003 From: theller at python.net (Thomas Heller) Date: Fri May 23 13:25:16 2003 Subject: [python-win32] Re: Can we add 'native COM support' to a 3rd party DLL/OLB References: <5D0355F204917248B054EDB0D57BD9E42AB9D4@oden.comopt.com> Message-ID: [cc to ctypes-users list] > > I have not really followed the discussion, but ctypes has support > > for vtable based interfaces. I'm currently writing some docs, you may > > want to check it out: > > > > http://starship.python.net/crew/theller/ctypes/ > > http://starship.python.net/crew/theller/ctypes/com.html > > http://starship.python.net/crew/theller/ctypes/sum_sample.html > > A quick read of the com.html and sum_sample.html is very interesting. > I'm currently having trouble sending events from pythoncom servers to VB > clients. Do you think the ctypes module will work better for me in this > regard. The only reference to events that I found in your docs was the > ctypes.com.connectionpoints module, which you say is for receiving > events. There's a sample which uses Internet Explorer with automation, and receives events over a connectionpoint. This is not yet in the docs. > > Actually my problem involves a design that I'm sure is not uncommon, and > I expect either PythonCOM or ctypes can solve it, but I've just not > figured out how. If you have any advice, I'd love to hear it. The > problem is I have a VB client (so single threaded apartment), and some > multithreaded python code that does a bunch of calculations, some of > which are time consuming. I want to glue the two together with COM such > that: > - VB CoCreates a python COM object which it calls to start the > calculation > - python creates a second thread to do the calculation, so the > 'StartCalcultion' is non-blocking. > - python thread signals the VB when it's finished (I've tried a callback > VB COM object, which sort of works, and then crashes after # calls, but > would probably prefer to use windows messages or some kind of events). >From what I understand this should be possible even with win32com, maybe Mark Hammond can comment on that. The ctypes COM stuff is pretty new and work in progress, currently it's not even possible to create inproc servers, but I'm working on that. Thomas From bra13 at gmx.de Sun May 25 20:53:40 2003 From: bra13 at gmx.de (Achim) Date: Sun May 25 20:31:04 2003 Subject: [python-win32] help Message-ID: <000e01c322e6$956a25d0$0300a8c0@chiefmaster> Hi, I have a problem to delete certain rows in Excel via python and to sort a sheet by column xyz !!!! do you have any examples for these two problems!!!!!!!! thx alot Achim -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20030525/e9dab944/attachment.htm From Andrew.MacIntyre at aba.gov.au Mon May 26 18:35:52 2003 From: Andrew.MacIntyre at aba.gov.au (Andrew MacIntyre) Date: Mon May 26 03:39:56 2003 Subject: [python-win32] Re: Can we add 'native COM support' to a 3rd p arty DLL/OLB Message-ID: > From: Thomas Heller > Sent: Friday, 23 May 2003 6:45 PM {...} > I have not really followed the discussion, but ctypes has support > for vtable based interfaces. I'm currently writing some docs, you may > want to check it out: > > http://starship.python.net/crew/theller/ctypes/ > http://starship.python.net/crew/theller/ctypes/com.html > http://starship.python.net/crew/theller/ctypes/sum_sample.html Well, this looks like it might be able to do what I want. I've generated the module interface files with readtlb.py. One of the libraries tripped readtlb.py by having references to VT_CARRAY (28) & VT_SAFEARRAY (27) which aren't (yet) supported in the TYPES dict. I fudged TYPES dict entries and it looks like the references to these types are in parts of the object model I don't plan to go near, so I think that's no problem. ArcGIS has a very extensive object hierarchy, and consequently most definitions are in a core object library, with the control libraries referring to interfaces & coclasses in the core object library. Consequently, I believe I have to manually modify the generated module interface files to import the right definitions in the right places. Each generated interface file has a small number of definitions (classes COMObject, enum, dispinterface & DISPMETHOD + module variables OLECMDID & OLECMDEXCEPT). With the need to import multiple modules, should these definitions be moved out of the interface files into a separately imported module? While it would be nice to be able to use Pythonwin & ctypes together, as far as I can make out there's no way to get a useful IUnknown pointer (to feed to ctypes) from Pythonwin's PyIUnknown objects. Just how to use ctypes for a control within another window, as distinct from the IE.Application example, eludes me at the moment... ----------------------------------------------------------------------- Andrew MacIntyre \ E-mail: andrew.macintyre@aba.gov.au Planning & Licensing Branch \ Tel: +61 2 6256 2812 Australian Broadcasting Authority \ Fax: +61 2 6253 3277 -> "These thoughts are mine alone!" <---------------------------------- From craig.taverner at comopt.com Mon May 26 12:29:59 2003 From: craig.taverner at comopt.com (Craig Taverner) Date: Mon May 26 05:27:56 2003 Subject: [python-win32] RE: Can we add 'native COM support' to a 3rd party DLL/OLB Message-ID: <5D0355F204917248B054EDB0D57BD9E42AB9D6@oden.comopt.com> > The Pythonwin docs refer to creating native interfaces via SWIG, and > the Pythonwin CVS contains a tweaked version of SWIG 1.1 for creating > the MAPI interfaces. > > Exactly what the mechanics of doing this aren't yet clear to me, but > I'm guessing that there must be a reasonable way to convert the type > library definitions to SWIG .i files. > > I'm further hampered by not having access to MSVC (I've been using > MinGW for the extensions I've done to date, including an Arc ODE > extension set). Sounds promising. Although I do have access to MSVC6 and .NET, I do not have access to much time, as the python side is currently still only a small part of our project. Perhaps you could point me directly to the SWIG references you have above, and I'll see if there's anything I can do in the short term. Since I know nothing really about python extensions (yet), the learning curve will be a definite delaying factor. From Christophe.Brunain at health.fgov.be Mon May 26 12:27:39 2003 From: Christophe.Brunain at health.fgov.be (Brunain Christophe) Date: Mon May 26 05:28:20 2003 Subject: [python-win32] py2exe problem with com Message-ID: <2C6114AD6C6B10418D0B505E08B51122034611@andromede.health.fgov.be> hello you all thanks for your help in my previous message, it was fine :o) Now, i've finished my script, it works good when i call it from the command line, but when i try to """compile""" it with py2exe, it fails the problem comes from the COM module that i use, because when i try to use py2exe after removing all the com stuff, it works here is the output from py2exe : running py2exe running build running build_scripts copying and adjusting unload2xls.py -> build\scripts-2.2 running install_scripts copying build\scripts-2.2\unload2xls.py -> build\bdist.win32\winexe\lib\python22 \Scripts +---------------------------------------------------- | Processing script unload2xls.py with py2exe-0.3.4 +---------------------------------------------------- Searching modules needed to run 'unload2xls.py' on path: ['C:\\test\\build\\bdist.win32\\winexe\\lib\\python22\\Lib\\site-packages', '', 'C:\\Python22\\lib\\site-packages\\Pythonwin', 'C:\\Python22\\lib\\site-packages \\win32', 'C:\\Python22\\lib\\site-packages\\win32\\lib', 'C:\\Python22\\lib\\si te-packages', 'c:\\python22\\DLLs', 'c:\\python22\\lib', 'c:\\python22\\lib\\lib -tk', 'c:\\python22'] Traceback (most recent call last): File "setup.py", line 6, in ? scripts=["unload2xls.py"], File "c:\python22\lib\distutils\core.py", line 138, in setup dist.run_commands() File "c:\python22\lib\distutils\dist.py", line 893, in run_commands self.run_command(cmd) File "c:\python22\lib\distutils\dist.py", line 913, in run_command cmd_obj.run() File "C:\Python22\Lib\site-packages\py2exe\build_exe.py", line 526, in run mf.run_script(script) File "C:\Python22\Lib\site-packages\py2exe\tools\modulefinder.py", line 122, i n run_script self.load_module('__main__', fp, pathname, stuff) File "C:\Python22\Lib\site-packages\py2exe\tools\modulefinder.py", line 291, i n load_module self.scan_code(co, m) File "C:\Python22\Lib\site-packages\py2exe\tools\modulefinder.py", line 311, i n scan_code self.import_hook(name, m) File "C:\Python22\Lib\site-packages\py2exe\tools\modulefinder.py", line 134, i n import_hook q, tail = self.find_head_package(parent, name) File "C:\Python22\Lib\site-packages\py2exe\tools\modulefinder.py", line 175, i n find_head_package q = self.import_module(head, qname, parent) File "C:\Python22\Lib\site-packages\py2exe\tools\modulefinder.py", line 261, i n import_module m = self.load_module(fqname, fp, pathname, stuff) File "C:\Python22\Lib\site-packages\py2exe\tools\modulefinder.py", line 291, i n load_module self.scan_code(co, m) File "C:\Python22\Lib\site-packages\py2exe\tools\modulefinder.py", line 311, i n scan_code self.import_hook(name, m) File "C:\Python22\Lib\site-packages\py2exe\tools\modulefinder.py", line 134, i n import_hook q, tail = self.find_head_package(parent, name) File "C:\Python22\Lib\site-packages\py2exe\tools\modulefinder.py", line 175, i n find_head_package q = self.import_module(head, qname, parent) File "C:\Python22\Lib\site-packages\py2exe\tools\modulefinder.py", line 261, i n import_module m = self.load_module(fqname, fp, pathname, stuff) File "C:\Python22\Lib\site-packages\py2exe\tools\modulefinder.py", line 276, i n load_module co = compile(fp.read()+'\n', pathname, 'exec') File "", line 1 from win32com.client import * ^ SyntaxError: invalid syntax have someone met this problem before ? thanks a lot Brunain Christophe Service informatique de l'expertise m?dicale SPF Sant? Publique, S?curit? de la chaine alimentaire et Environnement telephone : 02/287.05.71 email : christophe.brunain@health.fgov.be Rue de la Loi, 56 1040 Bruxelles From theller at python.net Mon May 26 10:35:54 2003 From: theller at python.net (Thomas Heller) Date: Mon May 26 05:35:55 2003 Subject: [python-win32] Re: py2exe problem with com References: <2C6114AD6C6B10418D0B505E08B51122034611@andromede.health.fgov.be> Message-ID: <4r3iyrri.fsf@python.net> Brunain Christophe writes: > Now, i've finished my script, it works good when i call it from the command > line, but when i try to """compile""" it with py2exe, it fails > [...] > n find_head_package > q = self.import_module(head, qname, parent) > File "C:\Python22\Lib\site-packages\py2exe\tools\modulefinder.py", line > 261, i > n import_module > m = self.load_module(fqname, fp, pathname, stuff) > File "C:\Python22\Lib\site-packages\py2exe\tools\modulefinder.py", line > 276, i > n load_module > co = compile(fp.read()+'\n', pathname, 'exec') > File "", line 1 > from win32com.client import * > ^ > SyntaxError: invalid syntax > > have someone met this problem before ? Could it be that your script has non-dos line endings? The compile function has problems with them, IIRC. Thomas From Andrew.MacIntyre at aba.gov.au Mon May 26 20:33:01 2003 From: Andrew.MacIntyre at aba.gov.au (Andrew MacIntyre) Date: Mon May 26 05:37:07 2003 Subject: [python-win32] Re: Can we add 'native COM support' to a 3rd p arty DLL/OLB Message-ID: > From: Andrew MacIntyre > Sent: Monday, 26 May 2003 5:36 PM {...} > While it would be nice to be able to use Pythonwin & ctypes together, > as far as I can make out there's no way to get a useful IUnknown > pointer (to feed to ctypes) from Pythonwin's PyIUnknown objects. You only see these things afterwards... ;-| The repr() of a PyIUnknown: ^^^^^^^^ Just parsing the repr() output should get an address for the object. I'll experiment a bit more tomorrow... BTW, I've encountered a couple of problems with the readtlb.py generated interface files: - a considerable number of out-of-order class definitions (I expect this is in the source .olb file, and not much you can do; I mention it in case someone else trips over it...); - there is one class in this particular object library that starts with 2 underscores - this causes a puzzling name error!; - there was a pointer definition that didn't get made, though I can see it in an IDL file generated from the same object library. I'm still wading through the re-ordering of this interface file (!3500 class defs, ~40000 lines)... Regards, Andrew. ----------------------------------------------------------------------- Andrew MacIntyre \ E-mail: andrew.macintyre@aba.gov.au Planning & Licensing Branch \ Tel: +61 2 6256 2812 Australian Broadcasting Authority \ Fax: +61 2 6253 3277 -> "These thoughts are mine alone!" <---------------------------------- From theller at python.net Mon May 26 10:46:21 2003 From: theller at python.net (Thomas Heller) Date: Mon May 26 05:46:23 2003 Subject: [python-win32] Re: Can we add 'native COM support' to a 3rd p arty DLL/OLB References: Message-ID: Andrew MacIntyre writes: > > From: Thomas Heller > > Sent: Friday, 23 May 2003 6:45 PM > > {...} > > > I have not really followed the discussion, but ctypes has support > > for vtable based interfaces. I'm currently writing some docs, you may > > want to check it out: > > > > http://starship.python.net/crew/theller/ctypes/ > > http://starship.python.net/crew/theller/ctypes/com.html > > http://starship.python.net/crew/theller/ctypes/sum_sample.html > > Well, this looks like it might be able to do what I want. > > I've generated the module interface files with readtlb.py. One of the > libraries tripped readtlb.py by having references to VT_CARRAY (28) & > VT_SAFEARRAY (27) which aren't (yet) supported in the TYPES dict. I > fudged TYPES dict entries and it looks like the references to these > types are in parts of the object model I don't plan to go near, so I > think that's no problem. > > ArcGIS has a very extensive object hierarchy, and consequently most > definitions are in a core object library, with the control libraries > referring to interfaces & coclasses in the core object library. > Consequently, I believe I have to manually modify the generated module > interface files to import the right definitions in the right places. > > Each generated interface file has a small number of definitions > (classes COMObject, enum, dispinterface & DISPMETHOD + module variables > OLECMDID & OLECMDEXCEPT). With the need to import multiple modules, > should these definitions be moved out of the interface files into > a separately imported module? On friday I cleaned up the generated output of readtlb.py quite a bit: I removed the OLECMDID and OLECMDEXCEPT hack which was only there because it didn't parse unions, class enum and class COMObject are also removed (enums now are a direct subclass of c_int, and readtlb generated coclasses don't have a base class any more), and the dispinterface and DISPMETHOD stuff went into ctypes.com.automation. If you want you can update from CVS, although there were other changes as well - non-working support for inproc servers which I hope to finish this or next week. > > While it would be nice to be able to use Pythonwin & ctypes together, > as far as I can make out there's no way to get a useful IUnknown > pointer (to feed to ctypes) from Pythonwin's PyIUnknown objects. I'll try to look into this. Mark, can you give a hint? > Just how to use ctypes for a control within another window, as distinct > from the IE.Application example, eludes me at the moment... Henk Punt's venster project has a 'ctypes window' which embeds the internet explorer as activex control, but I fear this is not what you mean;-) As soon as the inproc server stuff works, I'll add some axamples for primitive activex controls implemented in ctypes. Thomas From Christophe.Brunain at health.fgov.be Mon May 26 14:33:51 2003 From: Christophe.Brunain at health.fgov.be (Brunain Christophe) Date: Mon May 26 07:34:35 2003 Subject: [python-win32] Re: py2exe problem with com Message-ID: <2C6114AD6C6B10418D0B505E08B51122034613@andromede.health.fgov.be> it was that ! i don't understand why it was unix-style eof, but now that work !! thanks a lot ! > -----Message d'origine----- > De : Thomas Heller [mailto:theller@python.net] > Envoy? : lundi 26 mai 2003 11:36 > ? : python-win32@python.org > Objet : [python-win32] Re: py2exe problem with com > > > Brunain Christophe writes: > > > Now, i've finished my script, it works good when i call it > from the command > > line, but when i try to """compile""" it with py2exe, it fails > > > [...] > > > n find_head_package > > q = self.import_module(head, qname, parent) > > File > "C:\Python22\Lib\site-packages\py2exe\tools\modulefinder.py", line > > 261, i > > n import_module > > m = self.load_module(fqname, fp, pathname, stuff) > > File > "C:\Python22\Lib\site-packages\py2exe\tools\modulefinder.py", line > > 276, i > > n load_module > > co = compile(fp.read()+'\n', pathname, 'exec') > > File "", line 1 > > from win32com.client import * > > ^ > > SyntaxError: invalid syntax > > > > have someone met this problem before ? > > Could it be that your script has non-dos line endings? > The compile function has problems with them, IIRC. > > Thomas > > > _______________________________________________ > Python-win32 mailing list > Python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 > From theller at python.net Mon May 26 17:44:40 2003 From: theller at python.net (Thomas Heller) Date: Mon May 26 12:44:42 2003 Subject: [python-win32] Re: Can we add 'native COM support' to a 3rd p arty DLL/OLB In-Reply-To: References: Message-ID: Andrew MacIntyre writes: > > From: Andrew MacIntyre > > Sent: Monday, 26 May 2003 5:36 PM > > {...} > > > While it would be nice to be able to use Pythonwin & ctypes together, > > as far as I can make out there's no way to get a useful IUnknown > > pointer (to feed to ctypes) from Pythonwin's PyIUnknown objects. > > You only see these things afterwards... ;-| > > The repr() of a PyIUnknown: > > ^^^^^^^^ > > Just parsing the repr() output should get an address for the object. > I'll experiment a bit more tomorrow... Sounds hackish ;-), but if it works... > > BTW, I've encountered a couple of problems with the readtlb.py generated > interface files: > - a considerable number of out-of-order class definitions (I expect > this is in the source .olb file, and not much you can do; I mention > it in case someone else trips over it...); Are these for Structures/Unions? > - there is one class in this particular object library that starts with > 2 underscores - this causes a puzzling name error!; Should be fixed in readtlb, I guess > - there was a pointer definition that didn't get made, though I can see > it in an IDL file generated from the same object library. and this one also. > > I'm still wading through the re-ordering of this interface file (!3500 > class defs, ~40000 lines)... Sounds this is too much be be reordered manually. Maybe you can mail me the tlb file or, less useful, the generated py-file by private mail so I can look into this? Thomas From theller at python.net Fri May 30 16:49:08 2003 From: theller at python.net (Thomas Heller) Date: Fri May 30 11:49:09 2003 Subject: [python-win32] win32com command line flags, py2exe, installer, ... Message-ID: I was looking into improving support for win32com COM servers created with py2exe, and came up with the following questions: 1. Pythoncom uses the '--unregister' command line flag, and doesn't support a '--register' flag, registration is default. Why is this, instead of using the MS standard '/regserver' and '/unregserver' case insensitive flags? And why is the localserver registered with a /Automate flag, as I understand it localservers receive a '/Embedding' command line flag automatically when started by com (at least this is the result of my experiments on WinXP Pro). 2. Pythoncom uses a trivial approach looking for these command line flags, any unknown flags are simply ignored. Since it is impossible with the getopt module to parse windows style command lines correctly, I've written a simple w_getopt function which is able to do this. It is online at http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/ctypes/ctypes/win32/com/w_getopt.py?rev=HEAD&only_with_tag=HEAD&content-type=text/vnd.viewcvs-markup If the link is too long, here's a shorter one: http://tinyurl.com/d21n 3. The win32com.server.register module contains special stuff for supporting McMillan installer, and maybe also freeze. I suggest to invent a function like this (which can also be useful to the NT service module) to decide if the server must be started by python.exe (or pythonw.exe), or is contained in an executable built with py2exe, installer, cx_freeze or Python's freeze tool: def main_is_frozen(): import imp return (hasattr(sys, "frozen") # mcmillan installer or hasattr(sys, "importers") # py2exe or imp.is_frozen("__main__")) # freeze, cx_freeze Maybe a similar api can be provided for frozen inproc servers, which currently are only possible with mcmillan. 4. Why is win32com.server.register.UseCommandLine only used for registration and unregistration? Wouldn't it make more sense to use it also for starting the localserver, provided that /Embedding is used? Thomas (mainly offline until Monday)