From greg@electricrain.com Mon Jul 2 23:29:47 2001 From: greg@electricrain.com (Gregory P. Smith) Date: Mon, 2 Jul 2001 15:29:47 -0700 Subject: [python-win32] passing PIL generated image through COM for display in vb? Message-ID: <20010702152947.B27842@zot.electricrain.com> Does anyone know how to pass an image generated by PIL through COM for display via a VB gui? (without writing it to a file on disk) Or have any other suggestions on how to generate a bitmap in python for display via a gui written in another language using com? TIA, Greg From David.Ransier@digital2me.com Thu Jul 5 22:12:27 2001 From: David.Ransier@digital2me.com (David Ransier) Date: Thu, 5 Jul 2001 14:12:27 -0700 Subject: [python-win32] How to parse a binary file Message-ID: <013412396741D411879900D0B73C35920D3A6C@xchg-pdx-01.digital2me.com> I've never written a binary parser before, so I'm looking for some starting point. I want to read an image file (Sun Raster format: RAS) and parse the included color map, writing the color map as a text file (possible CSV format). I can open the file in "rb" mode and read a certain number of bytes. But when I try to do something with the value, Python complains that it's not in the correct format. Here is some sample code for reading the file (Magic is a 4-byte ID that identifies the file as RAS format.) import sys infile = "TestImage.ras" try: FH = open(infile, 'rb') except IOError, eStr: print "ERROR: Cannot open ", infile, " for reading: ", eStr sys.exit() Magic = FH.read(4) print "Magic: %d" % (Magic) I tried coercing Magic to an int, but that didn't help. Thanks, David R ____________________________________________ David Ransier David.Ransier@digital2me.com Office: 503-416-3812 111 SW 5th Ave. Fax: 503-416-3801 Suite 2200 Mobile: 360-921-5584 Portland, OR 97204 From jens.jorgensen@tallan.com Thu Jul 5 22:40:47 2001 From: jens.jorgensen@tallan.com (Jorgensen, Jens) Date: Thu, 05 Jul 2001 16:40:47 -0500 Subject: [python-win32] How to parse a binary file References: <013412396741D411879900D0B73C35920D3A6C@xchg-pdx-01.digital2me.com> Message-ID: <3B44DEDF.1080900@tallan.com> David Ransier wrote: >I've never written a binary parser before, so I'm looking for some starting >point. > >I want to read an image file (Sun Raster format: RAS) and parse the included >color map, writing the color map as a text file (possible CSV format). > >I can open the file in "rb" mode and read a certain number of bytes. But >when I try to do something with the value, Python complains that it's not in >the correct format. > >Here is some sample code for reading the file (Magic is a 4-byte ID that >identifies the file as RAS format.) > > > > >import sys > >infile = "TestImage.ras" >try: > FH = open(infile, 'rb') >except IOError, eStr: > print "ERROR: Cannot open ", infile, " for reading: ", eStr > sys.exit() > > Magic = FH.read(4) > print "Magic: %d" % (Magic) > > > > >I tried coercing Magic to an int, but that didn't help. > Well, this certainly isn't Win32 specific but what the heck. When you read data from a file it is *always* a string. In order to take this binary data and turn it into other things (like strings) you'll want to use the struct module. In the above case you could write: Magic = struct.unpack("i", FH.read(4))[0] -- Jens B. Jorgensen jens.jorgensen@tallan.com From BrianQ@ActiveState.com Thu Jul 5 22:54:51 2001 From: BrianQ@ActiveState.com (Brian Quinlan) Date: Thu, 5 Jul 2001 14:54:51 -0700 Subject: [python-win32] RE: How to parse a binary file In-Reply-To: <013412396741D411879900D0B73C35920D3A6C@xchg-pdx-01.digital2me.com> Message-ID: <001401c1059d$1e937870$b503a8c0@activestate.ca> > I've never written a binary parser before, so I'm looking for > some starting point. You should probably start by checking out the struct module (http://www.python.org/doc/current/lib/module-struct.html). If you need a concrete usage example, please let me know. Cheers, Brian -- Brian Quinlan Python and XSLT Developer BrianQ@ActiveState.com ASPN - ActiveState Programmer Network Essential programming tools and information http://aspn.ActiveState.com/ASPN From giant_lizard_of_death@hotmail.com Tue Jul 10 08:19:47 2001 From: giant_lizard_of_death@hotmail.com (Marc Miller) Date: Tue, 10 Jul 2001 00:19:47 -0700 Subject: [python-win32] ASP Python Message-ID: ------=_NextPart_001_0000_01C108D6.06A69AD0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Do people do serious ASP programming in Python? I've recently been doing= somewhat-serious ASP programming in Perl and have started investigating = Python as an alternative. The lack of thorough documentation and reasona= ble examples struck me, but that didn't stop me from entering the Perl AS= P world :-). Anyway, I've got two questions that maybe someone can help = me with. The first question deals with assigning to COM object properties which ta= ke arguments. A very similar question was asked in April by Gregory P. S= mith ("assigning vb properties from python via COM"). Consider the follo= wing piece of JScript code: // example JScript code Application('x') =3D 4; Response.Write(Application('x')); The output is "4". This example doesn't compile in python-land; you get = an error because you're assigning to the result of a function call. I th= ink there was some confusion on the other thread, so let me just expand o= n what's happening here: JScript is calling the default method on the app= lication object, "Value", so this is equivalent to the following JScript = code: // example JScript code Application.Value('x') =3D 4; Response.Write(Application('x')); JScript actually turns the assignment into a single COM call which is equ= ivalent to this pseudo-C++ code: // equivalent pseudo-C++ code VARIANT v =3D { 0 }; // put =E2=80=9C4=E2=80=9D inside a variant v.vt =3D VT_I4; v.lval =3D 4; BSTR bstrPropName =3D SysAllocString(=E2=80=9Cx=E2=80=9D); // assume pApplication is of type IApplicationObject (see asp.dll) pApplication->put_Value(bstrPropName, v); SysFreeString(bstrPropName); Anyway, Perl doesn=E2=80=99t have as sophisticated IDispatch integration = as Jscript does and cannot recognize something that looks like an assignm= ent to the result of a function call as a property put to the COM object = in question. So the Perl guys have this hack workaround which works grea= t (though it=E2=80=99s not terribly pretty): they implement a method on t= heir COM objects called =E2=80=9CSetProperty=E2=80=9D: # equivalent Perl code: $Application->SetProperty('Value', 'x', 4); $Response->Write($Application->Value('x')); Which brings me back to Python. I haven=E2=80=99t been able to find anyt= hing similar in Python. Fortunately, Python=E2=80=99s COM integration ha= s much more to it than Perl=E2=80=99s, so I can call the IDispatch direct= ly and do what I want. # equivalent Python code: o =3D Application._oleobj_; dispId =3D o.GetIDsOfNames('Value'); # perform the equivalent of Application('x') =3D 4 o.Invoke(dispId, 0x0, pythoncom.DISPATCH_PROPERTYPUT, 0, 'x', 4); Response.Write(Application('x')); Blech! Does anyone know a better way? Being able to store stuff in the application object, by the way, is reall= y useful for ASP programming (at least the stuff I=E2=80=99m working on).= It allows you to maintain a state across your web application from requ= est to request. The caveat is that anything you want to store in the App= lication object has to be able to fit inside a VARIANT. Futhermore, if t= he thingy you want to store is an object (like VT_DISPATCH), then it has = to be free-threaded (I=E2=80=99m not so sure about this restriction). Th= is is a bummer, because I would like to store Perl or Python=E2=80=99s ri= ch data structures in there. However, I was playing around with Python and noticed something strange. = Consider the following ASP script: <%@ LANGUAGE=3D"Python" %> <% import sys; if 'x' in dir(sys): Response.Write('x in dir %s' % sys.x); sys.x =3D sys.x + 1 else: Response.Write('x not in dir'); sys.x =3D 0 %> What happens on my server setup is cool: =E2=80=9Csys.x=E2=80=9D is a cou= nter of how many times I=E2=80=99ve refreshed the page. Anyone know what= =E2=80=99s going on here? I have a hunch this is just an implementation = side-effect and not by-design, but it would be really useful. I=E2=80=99m not subscribed to this list, so please copy me in any replies= . Thanks in advance! Marc MillerGet more from the Web. FREE MSN Explorer download : http://ex= plorer.msn.com ------=_NextPart_001_0000_01C108D6.06A69AD0 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
D= o people do serious ASP programming in Python?  I've recently been doing somewhat-serious ASP progra= mming in Perl and have started investigating Python as an alternative.  The lack of thorough documen= tation and reasonable examples struck me, but that didn't stop me from en= tering the Perl ASP world :-).  Anyway, I've got two questions that maybe someone can help me with.<= /SPAN>
<= SPAN style=3D"FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-fareast-fo= nt-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-langu= age: EN-US; mso-bidi-language: AR-SA"> 
The first question deals= with assigning to COM object properties which take arguments.  A very similar question was asked in= April by Gregory P. Smith ("assigning vb properties from python via COM"= ).  Consider the following = piece of JScript code:
 
=  // example JScript code
 Application('x') =3D 4;
 Response.Write(Appl= ication('x'));
 
The = output is "4".  This exampl= e doesn't compile in python-land; you get an error because you're assigni= ng to the result of a function call.&nb= sp; I think there was some confusion on the other thread, so let m= e just expand on what's happening here: JScript is calling the default me= thod on the application object, "Value", so this is equivalent to the fol= lowing JScript code:
=
 // example JScript code=
 Application.V= alue('x') =3D 4;
&n= bsp;Response.Write(Application('x'));
JScript actually turns the assignment into a sin= gle COM call which is equivalent to this pseudo-C++ code:
 
 // equivalent pseudo-C++ code
&= nbsp;VARIANT v =3D { 0 };   // put =E2=80=9C4=E2=80=9D inside a= variant
 v.vt      =3D VT_I4;
 = v.lval    =3D 4;
 
 BSTR  bstrPropName =3D SysAllocString(=E2=80=9Cx=E2=80=9D= );
 =
 // assume pAppli= cation is of type IApplicationObject (see asp.dll)
 pAppl= ication->put_Value(bstrPropName, v);
 
 SysFreeString(bstrPropName);
Anyway, Perl doesn=E2=80=99t have as sophisticated IDispatch= integration as Jscript does and cannot recognize something that looks li= ke an assignment to the result of a function call as a property put to th= e COM object in question.  = So the Perl guys have this hack workaround which works great (though it=E2= =80=99s not terribly pretty): they implement a method on their COM object= s called =E2=80=9CSetProperty=E2=80=9D:
 
 # equivalent Perl code:
 = $Application->SetProperty('Value', 'x', 4);
 $Response->Wri= te($Application->Value('x'));
 
Which brings me back to Python.  Fortunately, Python= =E2=80=99s COM integration has much more to it than Perl=E2=80=99s, so I = can call the IDispatch directly and do what I want.
 
 # equivalent Python code:<= BR> o      =3D Application._oleobj_;
&nb= sp;dispId =3D o.GetIDsOfNames('Value');
 
 # perform the equivalent of Application('x') =3D 4 o.Invoke(dispId, 0x0, pythoncom.DISPATCH_PROPERTYPUT, 0, = 'x', 4);
 R= esponse.Write(Application('x'));
 
Blech! 
Being able t= o store stuff in the application object, by the way, is really useful for= ASP programming (at least the stuff I=E2=80=99m working on).  It allows you to maintain a state acros= s your web application from request to request.  The caveat is that anything you want to store in th= e Application object has to be able to fit inside a VARIANT.  Futhermore, if the thingy you want to s= tore is an object (like VT_DISPATCH), then it has to be free-threaded (I=E2= =80=99m not so sure about this restriction).  This is a bummer, because I would like to store Perl o= r Python=E2=80=99s rich data structures in there.
 
However, I was playing around with Python and noticed something= strange.  Consider the fol= lowing ASP script:
 
 <%@ LANGUAGE=3D"Python" %>
 <%
 import sys;
 if 'x' in dir(sys):=
    Response.Write('x in dir %s' % sys.x);
   = sys.x =3D sys.x + 1
 else:
    Response.Write('x no= t in dir');
    sys.x =3D 0
 %>
 
What happens on my ser= ver setup is cool: =E2=80=9Csys.x=E2=80=9D is a counter of how many times= I=E2=80=99ve refreshed the page. = Anyone know what=E2=80=99s going on here?  I have a hunch this is just an implementation sid= e-effect and not by-design, but it would be really useful.<= /DIV>
 
I=E2=80=99m not subscribed to this list, so please cop= y me in any replies.
 
Thanks in advance!
 
Marc Miller

 


Get more from the Web. FREE MSN Explorer download : http://explorer.msn.com

------=_NextPart_001_0000_01C108D6.06A69AD0-- From Jim Abrams Tue Jul 10 15:12:55 2001 From: Jim Abrams (Jim Abrams) Date: Tue, 10 Jul 2001 10:12:55 -0400 Subject: [python-win32] ASP Python In-Reply-To: References: Message-ID: <9885969267.20010710101255@publishingresources.com> Hello MM> Do people do serious ASP programming in Python? I've recently been MM> doing somewhat-serious ASP programming in Perl and have started MM> investigating Python as an alternative. The lack of thorough MM> documentation and reasonable examples struck me, but that didn't stop me MM> from entering the Perl ASP world :-). Anyway, I've got two questions MM> that maybe someone can help me with. I do all my serious ASP programming in Python. MM> The first question deals with assigning to COM object properties which MM> take arguments. A very similar question was asked in April by Gregory MM> P. Smith ("assigning vb properties from python via COM"). Consider the MM> following piece of JScript code: MM> // example JScript code MM> Application('x') = 4; MM> Response.Write(Application('x')); MM> The output is "4". This example doesn't compile in python-land; you get MM> an error because you're assigning to the result of a function call. I MM> think there was some confusion on the other thread, so let me just MM> expand on what's happening here: JScript is calling the default method MM> on the application object, "Value", so this is equivalent to the MM> following JScript code: MM> // example JScript code MM> Application.Value('x') = 4; MM> Response.Write(Application('x')); MM> JScript actually turns the assignment into a single COM call which is MM> equivalent to this pseudo-C++ code: MM> // equivalent pseudo-C++ code MM> VARIANT v = { 0 }; // put 4 inside a variant MM> v.vt = VT_I4; MM> v.lval = 4; MM> BSTR bstrPropName = SysAllocString(x); MM> // assume pApplication is of type IApplicationObject (see asp.dll) MM> pApplication->put_Value(bstrPropName, v); MM> SysFreeString(bstrPropName); MM> Anyway, Perl doesnt have as sophisticated IDispatch integration as MM> Jscript does and cannot recognize something that looks like an MM> assignment to the result of a function call as a property put to the COM MM> object in question. So the Perl guys have this hack workaround which MM> works great (though its not terribly pretty): they implement a method MM> on their COM objects called SetProperty: MM> # equivalent Perl code: MM> $Application->SetProperty('Value', 'x', 4); MM> $Response->Write($Application->Value('x')); MM> Which brings me back to Python. I havent been able to find anything MM> similar in Python. Fortunately, Pythons COM integration has much more MM> to it than Perls, so I can call the IDispatch directly and do what I MM> want. MM> # equivalent Python code: MM> o = Application._oleobj_; MM> dispId = o.GetIDsOfNames('Value'); MM> # perform the equivalent of Application('x') = 4 MM> o.Invoke(dispId, 0x0, pythoncom.DISPATCH_PROPERTYPUT, 0, 'x', 4); MM> Response.Write(Application('x')); MM> Blech! Does anyone know a better way? Application.SetValue('x', 4) Session.SetValue('x', 4) I wrote a simple wrapper for each that maps __setitem__ to SetValue and makes things feel and look a touch better. MM> Being able to store stuff in the application object, by the way, is MM> really useful for ASP programming (at least the stuff Im working on). MM> It allows you to maintain a state across your web application from MM> request to request. The caveat is that anything you want to store in MM> the Application object has to be able to fit inside a VARIANT. Which, to my dislike, means no dictionaries. Although a quick dict.items() can go in, and mx.Tools has a function called dict() which will take the items() list and rebuild a dictionary at C-level speed. MM> Futhermore, if the thingy you want to store is an object (like MM> VT_DISPATCH), then it has to be free-threaded (Im not so sure about MM> this restriction). This is a bummer, because I would like to store Perl MM> or Pythons rich data structures in there. You can build Python COM objects and store them in Session and Application. MM> However, I was playing around with Python and noticed something strange. MM> Consider the following ASP script: MM> <%@ LANGUAGE="Python" %> MM> <% MM> import sys; MM> if 'x' in dir(sys): MM> Response.Write('x in dir %s' % sys.x); MM> sys.x = sys.x + 1 MM> else: MM> Response.Write('x not in dir'); MM> sys.x = 0 MM> %> MM> What happens on my server setup is cool: sys.x is a counter of how MM> many times Ive refreshed the page. Anyone know whats going on here? MM> I have a hunch this is just an implementation side-effect and not MM> by-design, but it would be really useful. The Python ASP engine caches the modules, so sys.x is actually shared (Application scope). This also has the side effect that if you want to get print to work, you could sys.stdout = SomeObject(Response) that maps to Response.Write, however this won't work since its Application-scope shared, and Response is page-level scope. I ended up doing print >> _out, my stuff, and did: from win32com.axscript.client.framework import SafeOutput _out = SafeOutput(Response) A couple more Python-ASP weirdisms. Response.End() doesn't work, Response.end() does. (normally all the other methods are capital, Response.Write, Server.MapPath, etc) Modules are cached, and the mechanism for noticing newer files doesn't work quite like regular python. You need to explicitly reload any modules that you're using after you change them. I created a reload.asp page where I keep all my reload statements. Check out the HTMLgen library, it does wonders for correcting the problem of html-inside code blocks. I.E if sys.x > 5: %><% else: %><% This doesn't work. Also, some strange calls don't return what you expect. objCN = Server.CreateObject("ADODB.Connection") objCN.open(dsn) objRS = objCN.Execute("select * etc") objRS now has a tuple of (, int) I have no idea what the int means, but you need to trim it away to get at the RecordSet object. This has happened in some other places as well with 3rd party COM-objects. MM> Im not subscribed to this list, so please copy me in any replies. MM> Thanks in advance! MM> Marc Miller Hope this helped somewhat. -- Jim Abrams Sr. Software Engineer Publishing Resources, Inc. 732.548.4609x22 jabrams@publishingresources.com From jens.jorgensen@tallan.com Tue Jul 10 15:30:58 2001 From: jens.jorgensen@tallan.com (Jorgensen, Jens) Date: Tue, 10 Jul 2001 09:30:58 -0500 Subject: [python-win32] ASP Python References: Message-ID: <3B4B11A2.3060705@tallan.com> --------------080505090300060204080400 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Marc Miller wrote: Do people do serious ASP programming in Python? I've recently been doing somewhat-serious ASP programming in Perl and have started investigating Python as an alternative. The lack of thorough documentation and reasonable examples struck me, but that didn't stop me from entering the Perl ASP world :-). Anyway, I've got two questions that maybe someone can help me with. The first question deals with assigning to COM object properties which take arguments. A very similar question was asked in April by Gregory P. Smith ("assigning vb properties from python via COM"). Consider the following piece of JScript code: // example JScript code Application('x') = 4; Response.Write(Application('x')); The output is "4". This example doesn't compile in python-land; you get an error because you're assigning to the result of a function call. I think there was some confusion on the other thread, so let me just expand on what's happening here: JScript is calling the default method on the application object, "Value", so this is equivalent to the following JScript code: // example JScript code Application.Value('x') = 4; Response.Write(Application('x')); JScript actually turns the assignment into a single COM call which is equivalent to this pseudo-C++ code: // equivalent pseudo-C++ code VARIANT v = { 0 }; // put “4” inside a variant v.vt = VT_I4; v.lval = 4; BSTR bstrPropName = SysAllocString(“x”); // assume pApplication is of type IApplicationObject (see asp.dll) pApplication->put_Value(bstrPropName, v); SysFreeString(bstrPropName); Anyway, Perl doesn’t have as sophisticated IDispatch integration as Jscript does and cannot recognize something that looks like an assignment to the result of a function call as a property put to the COM object in question. So the Perl guys have this hack workaround which works great (though it’s not terribly pretty): they implement a method on their COM objects called “SetProperty”: # equivalent Perl code: $Application->SetProperty('Value', 'x', 4); $Response->Write($Application->Value('x')); Which brings me back to Python. I haven’t been able to find anything similar in Python. Fortunately, Python’s COM integration has much more to it than Perl’s, so I can call the IDispatch directly and do what I want. # equivalent Python code: o = Application._oleobj_; dispId = o.GetIDsOfNames('Value'); # perform the equivalent of Application('x') = 4 o.Invoke(dispId, 0x0, pythoncom.DISPATCH_PROPERTYPUT, 0, 'x', 4); Response.Write(Application('x')); Blech! Does anyone know a better way? Yes indeed. Many times you'll run across objects which use odd semantics like this (Microsoft just *loves* to do this). When I do I like to use makepy.py. This script takes a type library and generates a set of wrapper objects for you. It generally does a slick job of handling stuff like this. This script is found in the win32com\client subdirectory of your Python installation. It's an interactive Tk app. Run it and it brings up a list of type libraries registered by the system. Just choose one and click ok and it'll generate a python module for the library. By default it puts the module into win32com\gen_py\{type lib guid}.py. Alternatively you can use the -o param to put it into a file of your choosing. So, I put mine into ASP.py and stored that somewhere in my python path. Now, usually when you've used makepy.py you create objects in the usual Python way, e.g. app = ASP.Application() but in this case the Application object already exists. We just want to create a Python Application object we generated from the type library and have it wrap this existing object so instead we say: app = ASP.Application(oobj=Application) If you look at the source of the ASP module you generated and check out the CoClassBaseClass you'll see that its __init__ method takes oobj as a named parameter for the object reference to use. If you don't supply one it creates a new instance of the object using the CLSID of the CoClass from the type library. So, using this I can now write: <%@ LANGUAGE=Python %> <% import sys sys.path.append('c:\\Python21\\local') import ASP app = ASP.Application(oobj=Application) num = app.Value('num') if not num : num = 0 Response.Write(num) app.SetValue('num', num+1) %> That is actual running code I used. Note that on my box c:\Python21\local is where I like to keep modules that I create. Ordinarily this gets picked up automatically for my scripts because I have it set in my environment as PYTHONPATH but IIS doesn't get my environment so I add it manually. Being able to store stuff in the application object, by the way, is really useful for ASP programming (at least the stuff I’m working on). It allows you to maintain a state across your web application from request to request. The caveat is that anything you want to store in the Application object has to be able to fit inside a VARIANT. Futhermore, if the thingy you want to store is an object (like VT_DISPATCH), then it has to be free-threaded (I’m not so sure about this restriction). I believe the case is not that the object has to be free-threaded but that if it isn't then you lock that worker thread to a specific session (greatly hindering scalability). I'm not positive these are the exact semantics but its something like this. This is a bummer, because I would like to store Perl or Python’s rich data structures in there. Perhaps pickle or something like that is in order? You could serialize to a string and then rehydrate in your object. However, I was playing around with Python and noticed something strange. Consider the following ASP script: <%@ LANGUAGE="Python" %> <% import sys; if 'x' in dir(sys): Response.Write('x in dir %s' % sys.x); sys.x = sys.x + 1 else: Response.Write('x not in dir'); sys.x = 0 %> What happens on my server setup is cool: “sys.x” is a counter of how many times I’ve refreshed the page. Anyone know what’s going on here? I have a hunch this is just an implementation side-effect and not by-design, but it would be really useful. This sounds dangerous and unintended to me but I don't really have a clue. I’m not subscribed to this list, so please copy me in any replies. Perhaps you should consider joining. It's low volume and I'm guessing you might learn a few valuable tidbits here and there. -- Jens B. Jorgensen jens.jorgensen@tallan.com --------------080505090300060204080400 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit Marc Miller wrote:
Do people do serious ASP programming in Python?   I've recently been doing somewhat-serious ASP programming in Perl and have started investigating Python as an alternative.   The lack of thorough documentation and reasonable examples struck me, but that didn't stop me from entering the Perl ASP world :-).   Anyway, I've got two questions that maybe someone can help me with.
 
The first question deals with assigning to COM object properties which take arguments.  A very similar question was asked in April by Gregory P. Smith ("assigning vb properties from python via COM").  Consider the following piece of JScript code:
 
 // example JScript code
 Application('x') = 4;
 Response.Write(Application('x'));
 
The output is "4".  This example doesn't compile in python-land; you get an error because you're assigning to the result of a function call.  I think there was some confusion on the other thread, so let me just expand on what's happening here: JScript is calling the default method on the application object, "Value", so this is equivalent to the following JScript code:

 // example JScript code
 Application.Value('x') = 4;
 Response.Write(Application('x'));
JScript actually turns the assignment into a single COM call which is equivalent to this pseudo-C++ code:
 
 // equivalent pseudo-C++ code
 VARIANT v = { 0 };   // put “4” inside a variant
 v.vt      = VT_I4;
 v.lval    = 4;
 
 BSTR  bstrPropName = SysAllocString(“x”);
 
 // assume pApplication is of type IApplicationObject (see asp.dll)
 pApplication->put_Value(bstrPropName, v);
 
 SysFreeString(bstrPropName);
Anyway, Perl doesn’t have as sophisticated IDispatch integration as Jscript does and cannot recognize something that looks like an assignment to the result of a function call as a property put to the COM object in question.   So the Perl guys have this hack workaround which works great (though it’s not terribly pretty): they implement a method on their COM objects called “SetProperty”:
 
 # equivalent Perl code:
 $Application->SetProperty('Value', 'x', 4);
 $Response->Write($Application->Value('x'));
 
Which brings me back to Python.  I haven’t been able to find anything similar in Python.   Fortunately, Python’s COM integration has much more to it than Perl’s, so I can call the IDispatch directly and do what I want.
 
 # equivalent Python code:
 o      = Application._oleobj_;
 dispId = o.GetIDsOfNames('Value');
 
 # perform the equivalent of Application('x') = 4
 o.Invoke(dispId, 0x0, pythoncom.DISPATCH_PROPERTYPUT, 0, 'x', 4);
 
 Response.Write(Application('x'));
 
Blech!  Does anyone know a better way?
Yes indeed. Many times you'll run across objects which use odd semantics like this (Microsoft just *loves* to do this). When I do I like to use makepy.py. This script takes a type library and generates a set of wrapper objects for you. It generally does a slick job of handling stuff like this.  This script is found in the win32com\client subdirectory of your Python installation. It's an interactive Tk app. Run it and it brings up a list of type libraries registered by the system. Just choose one and click ok and it'll generate a python module for the library. By default it puts the module into win32com\gen_py\{type lib guid}.py. Alternatively you can use the -o param to put it into a file of your choosing. So, I put mine into ASP.py and stored that somewhere in my python path. Now, usually when you've used makepy.py you create objects in the usual Python way, e.g.

app = ASP.Application()

but in this case the Application object already exists. We just want to create a Python Application object we generated from the type library and have it wrap this existing object so instead we say:

app = ASP.Application(oobj=Application)

If you look at the source of the ASP module you generated and check out the CoClassBaseClass you'll see that its __init__ method takes oobj as a named parameter for the object reference to use. If you don't supply one it creates a new instance of the object using the CLSID of the CoClass from the type library. So, using this I can now write:

<%@ LANGUAGE=Python %>
<html>
<body>
<%
import sys

sys.path.append('c:\\Python21\\local')

import ASP

app = ASP.Application(oobj=Application)

num = app.Value('num')
if not num :
    num = 0

Response.Write(num)

app.SetValue('num', num+1)
%>
</body>
</html>


That is actual running code I used. Note that on my box c:\Python21\local is where I like to keep modules that I create. Ordinarily this gets picked up automatically for my scripts because I have it set in my environment as PYTHONPATH but IIS doesn't get my environment so I add it manually.

 
Being able to store stuff in the application object, by the way, is really useful for ASP programming (at least the stuff I’m working on).   It allows you to maintain a state across your web application from request to request.  The caveat is that anything you want to store in the Application object has to be able to fit inside a VARIANT.  Futhermore, if the thingy you want to store is an object (like VT_DISPATCH), then it has to be free-threaded (I’m not so sure about this restriction).  
I believe the case is not that the object has to be free-threaded but that if it isn't then you lock that worker thread to a specific session (greatly hindering scalability). I'm not positive these are the exact semantics but its something like this.
This is a bummer, because I would like to store Perl or Python’s rich data structures in there.
Perhaps pickle or something like that is in order? You could serialize to a string and then rehydrate in your object.
However, I was playing around with Python and noticed something strange.   Consider the following ASP script:
 
 <%@ LANGUAGE="Python" %>
 <%
 import sys;
 if 'x' in dir(sys):
    Response.Write('x in dir %s' % sys.x);
    sys.x = sys.x + 1
 else:
    Response.Write('x not in dir');
    sys.x = 0
 %>
 
What happens on my server setup is cool: “sys.x” is a counter of how many times I’ve refreshed the page.  Anyone know what’s going on here?  I have a hunch this is just an implementation side-effect and not by-design, but it would be really useful.
This sounds dangerous and unintended to me but I don't really have a clue.
I’m not subscribed to this list, so please copy me in any replies.
Perhaps you should consider joining. It's low volume and I'm guessing you might learn a few valuable tidbits here and there.

-- 
Jens B. Jorgensen
jens.jorgensen@tallan.com

--------------080505090300060204080400-- From niki@vintech.bg Tue Jul 10 15:37:24 2001 From: niki@vintech.bg (Niki Spahiev) Date: Tue, 10 Jul 2001 17:37:24 +0300 Subject: [python-win32] Q: how to debug COM servers Message-ID: <3B4B1324.5020500@vintech.bg> Hello, any hints on debuging Python COM servers except trace collector? regards, Niki Spahiev From jens.jorgensen@tallan.com Tue Jul 10 15:40:14 2001 From: jens.jorgensen@tallan.com (Jorgensen, Jens) Date: Tue, 10 Jul 2001 09:40:14 -0500 Subject: [python-win32] ASP Python Message-ID: <3B4B13CE.3080709@tallan.com> Jim Abrams wrote: >Also, some strange calls don't return what you expect. >objCN = Server.CreateObject("ADODB.Connection") >objCN.open(dsn) >objRS = objCN.Execute("select * etc") >objRS now has a tuple of (, int) >I have no idea what the int means, but you need to trim it away to get >at the RecordSet object. > Ok, well I obviously didn't know that Application wasn't just a simple Dispatch object in asps but this one I do know! The reason Execute returns a tuple is because Execute has an [out] parameter which returns the number of rows affected. Here's the clip from OLEVIEW: _Recordset* Execute( [in] BSTR CommandText, [out, optional] VARIANT* RecordsAffected, [in, optional, defaultvalue(-1)] long Options); Any COM [out] parameter will be returned from the method since in Python parameters are passed by value rather than by reference (we won't talk about object references). -- Jens B. Jorgensen jens.jorgensen@tallan.com From Jim.Vickroy@noaa.gov Tue Jul 10 19:18:38 2001 From: Jim.Vickroy@noaa.gov (Jim Vickroy) Date: Tue, 10 Jul 2001 12:18:38 -0600 Subject: [python-win32] Puzzling Event Log entry Message-ID: <3B4B46FE.80FD924A@noaa.gov> Hello all, I'm attempting to create "services" and have them place messages in the Event Log. Here is the initial portion of my "run" method for a service: def SvcDoRun (self): """ Perpetually: deletes *old* files in the receiving dock pauses a fixed interval of time Responds to a STOP request by exiting the perpetual loop and returning. """ # Put: "service started" message in Win Event Log. import servicemanager servicemanager.LogInfoMsg ('SXI receiving dock scrubber started.') # Remainder of implementation here. When the service, containing the above method, is started, the "Properties" attribute of the event log entry contains the following message: ------------------------------ The description for Event ID ( 255 ) in Source ( PythonService ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. The following information is part of the event: SXI receiving dock scrubber started. ------------------------------ Note, my 'SXI receiving dock scrubber started.' message is there, but there is also some sort of problem. What have I overlooked? My setup is: Python 2.0 win32 extensions Windows 2000 Thanks for your time. From jens.jorgensen@tallan.com Tue Jul 10 20:01:58 2001 From: jens.jorgensen@tallan.com (Jorgensen, Jens) Date: Tue, 10 Jul 2001 14:01:58 -0500 Subject: [python-win32] Puzzling Event Log entry References: <3B4B46FE.80FD924A@noaa.gov> Message-ID: <3B4B5126.40100@tallan.com> This isn't really a problem. Note the actual API call for reporting an event: BOOL ReportEvent( HANDLE hEventLog, // handle to event log WORD wType, // event type WORD wCategory, // event category DWORD dwEventID, // event identifier PSID lpUserSid, // user security identifier WORD wNumStrings, // number of strings to merge DWORD dwDataSize, // size of binary data LPCTSTR *lpStrings, // array of strings to merge LPVOID lpRawData // binary data buffer ); It's got a lot more than just a string. The call you are making likely just passes 255 for the dwEventID, which the event logging api expects to be an index to look up a message from and there's no message there. You can just ignore this--it doesn't mean that anything's wrong. Jim Vickroy wrote: >Hello all, > >I'm attempting to create "services" and have them place messages in the >Event Log. > >Here is the initial portion of my "run" method for a service: > > def SvcDoRun (self): > """ > Perpetually: > deletes *old* files in the receiving dock > pauses a fixed interval of time > > Responds to a STOP request by exiting the perpetual loop and >returning. > """ > > # Put: "service started" message in Win Event Log. > import servicemanager > servicemanager.LogInfoMsg ('SXI receiving dock scrubber started.') > > # Remainder of implementation here. > >When the service, containing the above method, is started, the >"Properties" attribute of the event log entry contains the following >message: > >------------------------------ >The description for Event ID ( 255 ) in Source ( PythonService ) cannot >be found. The local computer may not have the necessary registry >information or message DLL files to display messages from a remote >computer. The following information is part of the event: SXI receiving >dock scrubber started. >------------------------------ > >Note, my 'SXI receiving dock scrubber started.' message is there, but >there is also some sort of problem. What have I overlooked? > >My setup is: > >Python 2.0 >win32 extensions >Windows 2000 > >Thanks for your time. > > > >_______________________________________________ >Python-win32 mailing list >Python-win32@python.org >http://mail.python.org/mailman/listinfo/python-win32 > -- Jens B. Jorgensen jens.jorgensen@tallan.com From Jim.Vickroy@noaa.gov Tue Jul 10 20:11:46 2001 From: Jim.Vickroy@noaa.gov (Jim Vickroy) Date: Tue, 10 Jul 2001 13:11:46 -0600 Subject: [python-win32] Puzzling Event Log entry References: <3B4B46FE.80FD924A@noaa.gov> <3B4B5126.40100@tallan.com> Message-ID: <3B4B5372.7E22BCC9@noaa.gov> Thanks for your reply. If I understand you, it seems there is no way to prevent that "preface" to my message from appearing in the event log. Too bad; its sure to cause some confusion in the future for the uninitiated. "Jorgensen, Jens" wrote: > This isn't really a problem. Note the actual API call for reporting an > event: > > BOOL ReportEvent( > HANDLE hEventLog, // handle to event log > WORD wType, // event type > WORD wCategory, // event category > DWORD dwEventID, // event identifier > PSID lpUserSid, // user security identifier > WORD wNumStrings, // number of strings to merge > DWORD dwDataSize, // size of binary data > LPCTSTR *lpStrings, // array of strings to merge > LPVOID lpRawData // binary data buffer > ); > > It's got a lot more than just a string. The call you are making likely > just passes 255 for the dwEventID, which the event logging api expects > to be an index to look up a message from and there's no message there. > You can just ignore this--it doesn't mean that anything's wrong. > > Jim Vickroy wrote: > > >Hello all, > > > >I'm attempting to create "services" and have them place messages in the > >Event Log. > > > >Here is the initial portion of my "run" method for a service: > > > > def SvcDoRun (self): > > """ > > Perpetually: > > deletes *old* files in the receiving dock > > pauses a fixed interval of time > > > > Responds to a STOP request by exiting the perpetual loop and > >returning. > > """ > > > > # Put: "service started" message in Win Event Log. > > import servicemanager > > servicemanager.LogInfoMsg ('SXI receiving dock scrubber started.') > > > > # Remainder of implementation here. > > > >When the service, containing the above method, is started, the > >"Properties" attribute of the event log entry contains the following > >message: > > > >------------------------------ > >The description for Event ID ( 255 ) in Source ( PythonService ) cannot > >be found. The local computer may not have the necessary registry > >information or message DLL files to display messages from a remote > >computer. The following information is part of the event: SXI receiving > >dock scrubber started. > >------------------------------ > > > >Note, my 'SXI receiving dock scrubber started.' message is there, but > >there is also some sort of problem. What have I overlooked? > > > >My setup is: > > > >Python 2.0 > >win32 extensions > >Windows 2000 > > > >Thanks for your time. > > > > > > > >_______________________________________________ > >Python-win32 mailing list > >Python-win32@python.org > >http://mail.python.org/mailman/listinfo/python-win32 > > > > -- > Jens B. Jorgensen > jens.jorgensen@tallan.com From jens.jorgensen@tallan.com Tue Jul 10 20:49:33 2001 From: jens.jorgensen@tallan.com (Jorgensen, Jens) Date: Tue, 10 Jul 2001 14:49:33 -0500 Subject: [python-win32] Puzzling Event Log entry References: <3B4B46FE.80FD924A@noaa.gov> <3B4B5126.40100@tallan.com> <3B4B5372.7E22BCC9@noaa.gov> Message-ID: <3B4B5C4D.3060200@tallan.com> Actually there is a way. You can use LogMsg instead and specify a message ID and provide a message file. I've never done this myself so I'm not sure how the file is supposed to be set up, where it's supposed to go, etc. but this is the 'right' way to log event messages. Jim Vickroy wrote: >Thanks for your reply. > >If I understand you, it seems there is no way to prevent that "preface" to >my message from appearing in the event log. Too bad; its sure to cause some >confusion in the future for the uninitiated. > > >"Jorgensen, Jens" wrote: > >>This isn't really a problem. Note the actual API call for reporting an >>event: >> >>BOOL ReportEvent( >> HANDLE hEventLog, // handle to event log >> WORD wType, // event type >> WORD wCategory, // event category >> DWORD dwEventID, // event identifier >> PSID lpUserSid, // user security identifier >> WORD wNumStrings, // number of strings to merge >> DWORD dwDataSize, // size of binary data >> LPCTSTR *lpStrings, // array of strings to merge >> LPVOID lpRawData // binary data buffer >>); >> >>It's got a lot more than just a string. The call you are making likely >>just passes 255 for the dwEventID, which the event logging api expects >>to be an index to look up a message from and there's no message there. >>You can just ignore this--it doesn't mean that anything's wrong. >> >>Jim Vickroy wrote: >> >>>Hello all, >>> >>>I'm attempting to create "services" and have them place messages in the >>>Event Log. >>> >>>Here is the initial portion of my "run" method for a service: >>> >>>def SvcDoRun (self): >>> """ >>> Perpetually: >>> deletes *old* files in the receiving dock >>> pauses a fixed interval of time >>> >>> Responds to a STOP request by exiting the perpetual loop and >>>returning. >>> """ >>> >>> # Put: "service started" message in Win Event Log. >>> import servicemanager >>> servicemanager.LogInfoMsg ('SXI receiving dock scrubber started.') >>> >>> # Remainder of implementation here. >>> >>>When the service, containing the above method, is started, the >>>"Properties" attribute of the event log entry contains the following >>>message: >>> >>>------------------------------ >>>The description for Event ID ( 255 ) in Source ( PythonService ) cannot >>>be found. The local computer may not have the necessary registry >>>information or message DLL files to display messages from a remote >>>computer. The following information is part of the event: SXI receiving >>>dock scrubber started. >>>------------------------------ >>> >>>Note, my 'SXI receiving dock scrubber started.' message is there, but >>>there is also some sort of problem. What have I overlooked? >>> >>>My setup is: >>> >>>Python 2.0 >>>win32 extensions >>>Windows 2000 >>> >>>Thanks for your time. >>> >>> >>> >>>_______________________________________________ >>>Python-win32 mailing list >>>Python-win32@python.org >>>http://mail.python.org/mailman/listinfo/python-win32 >>> >>-- >>Jens B. Jorgensen >>jens.jorgensen@tallan.com >> -- Jens B. Jorgensen jens.jorgensen@tallan.com From Jim Abrams Wed Jul 11 21:45:23 2001 From: Jim Abrams (Jim Abrams) Date: Wed, 11 Jul 2001 16:45:23 -0400 Subject: Re[2]: [python-win32] ASP Python In-Reply-To: <9885969267.20010710101255@publishingresources.com> References: <9885969267.20010710101255@publishingresources.com> Message-ID: <86195917444.20010711164523@publishingresources.com> MM>> Being able to store stuff in the application object, by the way, is MM>> really useful for ASP programming (at least the stuff Im working on). MM>> It allows you to maintain a state across your web application from MM>> request to request. The caveat is that anything you want to store in MM>> the Application object has to be able to fit inside a VARIANT. JA> Which, to my dislike, means no dictionaries. Although a quick JA> dict.items() can go in, and mx.Tools has a function called dict() JA> which will take the items() list and rebuild a dictionary at C-level JA> speed. MM>> Futhermore, if the thingy you want to store is an object (like MM>> VT_DISPATCH), then it has to be free-threaded (Im not so sure about MM>> this restriction). This is a bummer, because I would like to store Perl MM>> or Pythons rich data structures in there. Something was tickling the back of my mind when I read this, and here's a suggestion. Since Python modules are cached, you could create an empty module, and use that as a replacement for the Application object's persistence mechanism. You'd have to work about it being thread-safe, but you can store arbitrary Python objects there. Infact it would probably be easy to create a Session manager as well using the same idea. Anyone know why this might not be a good idea? Some crude, quick tests showed the Python module to be about twice as fast as Session. If anyone does anything with this it would be helpful to post some results and ideas. From SyverE@cyberwatcher.com Thu Jul 12 18:10:32 2001 From: SyverE@cyberwatcher.com (Syver Enstad) Date: Thu, 12 Jul 2001 19:10:32 +0200 Subject: [python-win32] Puzzling Event Log entry Message-ID: > -----Original Message----- > From: Jim Vickroy [mailto:Jim.Vickroy@noaa.gov] > > Note, my 'SXI receiving dock scrubber started.' message is there, but > there is also some sort of problem. What have I overlooked? You have to register PythonService.exe like this: pythonservice.exe /register (PythonService.exe is located in your .\win32 folder where current dir is the python folder.) This registers the ID's so that you won't get the errormessages. From Jim.Vickroy@noaa.gov Thu Jul 12 18:28:44 2001 From: Jim.Vickroy@noaa.gov (Jim Vickroy) Date: Thu, 12 Jul 2001 11:28:44 -0600 Subject: [python-win32] Puzzling Event Log entry References: Message-ID: <3B4DDE4C.51C5E160@noaa.gov> Thank-you very much. That fixed the problem. Syver Enstad wrote: > > -----Original Message----- > > From: Jim Vickroy [mailto:Jim.Vickroy@noaa.gov] > > > > > Note, my 'SXI receiving dock scrubber started.' message is there, but > > there is also some sort of problem. What have I overlooked? > > You have to register PythonService.exe like this: > pythonservice.exe /register > > (PythonService.exe is located in your .\win32 folder where current dir is > the python folder.) > > This registers the ID's so that you won't get the errormessages. From john_hopkins@bigfoot.com Sun Jul 15 06:28:41 2001 From: john_hopkins@bigfoot.com (John Hopkins) Date: Sat, 14 Jul 2001 22:28:41 -0700 Subject: [python-win32] MySQLdb AttributeError Problem Message-ID: <005a01c10cef$029327c0$01000059@hopkinsmain> This is a multi-part message in MIME format. ------=_NextPart_000_0057_01C10CB4.55863570 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I have an interesting (OK, frustating) problem. I've been developing on = Win98, successfully connecting to a MySQL database via MySQLdb. I = recently installed Win2K Pro on my development machine in dual-boot = mode. I installed ActivePython 2.10.210, MySQLdb 0.3.5 and MySQL = 3.23.38 under Win2K. MySQL works fine, MySQLFront connects, lets me = browse tables, etc. so I know the server is doing its job. However, I haven't been able to connect to the database via MySQLdb. I = have a little Python script I originally used to learn how to handle the = data returned by a cursor within Python, called "testdb_list.py" Here's = a code snippet: __________________________________________ import sys import traceback sys.stderr =3D sys.stdout import MySQLdb try: ThisDB =3D MySQLdb.Connect(db=3D'LabTracker') except: traceback.print_exc() sys.exit() ____________________________________________ Running this code (from within PythonWin) worked fine this morning, and = I went on to get a cursor, etc. Now, I get the following traceback: =20 File "C:\My Documents\Dev Stuff\testdb_list.py", line 8, in ? ThisDB =3D MySQLdb.connect(db=3D'LabTracker') AttributeError: 'MySQLdb' module has no attribute 'Connect' =20 I looked through MySQLdb.py and the statement "Connect =3D connect =3D = Connection" is right where I expected it to be. I've also tried the = same code replacing "Connect" with "Connection" and "connect", to no = avail. I'm trying to finish up a project which will involve = installation on WinNT 4.0 (which is why I'm fiddling with Win2K; it's = the closet thing I have to the NT 4 environment), so any help will be = tremendously appreciated! =20 Thanks in advance, =20 John Hopkins john@hopkinsit.com ------=_NextPart_000_0057_01C10CB4.55863570 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I have an interesting (OK, frustating)=20 problem.  I've been developing on Win98, successfully = connecting to a=20 MySQL database via MySQLdb.  I recently installed Win2K Pro on my=20 development machine in dual-boot mode.  I installed ActivePython=20 2.10.210, MySQLdb 0.3.5 and MySQL 3.23.38 under Win2K.  MySQL = works=20 fine, MySQLFront connects, lets me browse tables, etc. so I know the = server is=20 doing its job.
 
However, I haven't been able to connect = to the=20 database via MySQLdb.  I have a little Python script I originally = used to=20 learn how to handle the data returned by a cursor within Python, called=20 "testdb_list.py" Here's a code snippet:
__________________________________________
import sys
import = traceback
sys.stderr =3D=20 sys.stdout
import MySQLdb
try:
    ThisDB =3D=20 MySQLdb.Connect(db=3D'LabTracker')
except:
    =    =20 traceback.print_exc()
       =20 sys.exit()
____________________________________________
 
Running this code (from within = PythonWin) worked=20 fine this morning, and I went on to get a cursor, etc.  Now, I get = the=20 following traceback:
 
  File "C:\My Documents\Dev=20 Stuff\testdb_list.py", line 8, in ?
    ThisDB =3D=20 MySQLdb.connect(db=3D'LabTracker')
AttributeError: 'MySQLdb' module = has no=20 attribute 'Connect'
 
I looked through MySQLdb.py and the = statement=20 "Connect =3D connect =3D Connection" is right where I expected it to = be.  I've=20 also tried the same code replacing "Connect" with "Connection" and = "connect", to=20 no avail.  I'm trying to finish up a project which will involve=20 installation on WinNT 4.0 (which is why I'm fiddling with Win2K; it's = the closet=20 thing I have to the NT 4 environment), so any help will be tremendously=20 appreciated!
 
Thanks in advance,
 
John Hopkins
john@hopkinsit.com
------=_NextPart_000_0057_01C10CB4.55863570-- From Jim.Vickroy@noaa.gov Mon Jul 16 15:25:18 2001 From: Jim.Vickroy@noaa.gov (Jim Vickroy) Date: Mon, 16 Jul 2001 08:25:18 -0600 Subject: [python-win32] MySQLdb AttributeError Problem References: <005a01c10cef$029327c0$01000059@hopkinsmain> Message-ID: <3B52F94E.3EEA9D68@noaa.gov> --------------CE331CB0FA7FF8B594568D45 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hello John, I tried to respond to this over the weekend from home, but I never saw it posted so forgive me if this is a duplicate. Two or three months ago, I was not able to get MySQLdb to work with ActivePython, but it did work fine with the "standard" distributions (1.5.2 and 2.0). If you have not done so, I would suggest trying Python 2.0 or 2.1 from http://www.python.org/. John Hopkins wrote: > I have an interesting (OK, frustating) problem. I've been developing > on Win98, successfully connecting to a MySQL database via MySQLdb. I > recently installed Win2K Pro on my development machine in dual-boot > mode. I installed ActivePython 2.10.210, MySQLdb 0.3.5 and MySQL > 3.23.38 under Win2K. MySQL works fine, MySQLFront connects, lets me > browse tables, etc. so I know the server is doing its job. However, I > haven't been able to connect to the database via MySQLdb. I have a > little Python script I originally used to learn how to handle the data > returned by a cursor within Python, called "testdb_list.py" Here's a > code snippet:__________________________________________import sys > import traceback > sys.stderr = sys.stdout > import MySQLdbtry: > ThisDB = MySQLdb.Connect(db='LabTracker') > except: > traceback.print_exc() > sys.exit() > ____________________________________________ Running this code (from > within PythonWin) worked fine this morning, and I went on to get a > cursor, etc. Now, I get the following traceback: File "C:\My > Documents\Dev Stuff\testdb_list.py", line 8, in ? > ThisDB = MySQLdb.connect(db='LabTracker') > AttributeError: 'MySQLdb' module has no attribute 'Connect' I looked > through MySQLdb.py and the statement "Connect = connect = Connection" > is right where I expected it to be. I've also tried the same code > replacing "Connect" with "Connection" and "connect", to no avail. I'm > trying to finish up a project which will involve installation on WinNT > 4.0 (which is why I'm fiddling with Win2K; it's the closet thing I > have to the NT 4 environment), so any help will be tremendously > appreciated! Thanks in advance, John Hopkinsjohn@hopkinsit.com --------------CE331CB0FA7FF8B594568D45 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Hello John,

I tried to respond to this over the weekend from home, but I never saw it posted so forgive me if this is a duplicate.

Two or three months ago, I was not able to get MySQLdb to work with ActivePython, but it did work fine with the "standard" distributions (1.5.2 and 2.0).

If you have not done so, I would suggest trying Python 2.0 or 2.1 from http://www.python.org/.

John Hopkins wrote:

I have an interesting (OK, frustating) problem.  I've been developing on Win98, successfully connecting to a MySQL database via MySQLdb.  I recently installed Win2K Pro on my development machine in dual-boot mode.  I installed ActivePython 2.10.210, MySQLdb 0.3.5 and MySQL 3.23.38 under Win2K.  MySQL works fine, MySQLFront connects, lets me browse tables, etc. so I know the server is doing its job. However, I haven't been able to connect to the database via MySQLdb.  I have a little Python script I originally used to learn how to handle the data returned by a cursor within Python, called "testdb_list.py" Here's a code snippet:__________________________________________import sys
import traceback
sys.stderr = sys.stdout
import MySQLdbtry:
    ThisDB = MySQLdb.Connect(db='LabTracker')
except:
        traceback.print_exc()
        sys.exit()
____________________________________________ Running this code (from within PythonWin) worked fine this morning, and I went on to get a cursor, etc.  Now, I get the following traceback:   File "C:\My Documents\Dev Stuff\testdb_list.py", line 8, in ?
    ThisDB = MySQLdb.connect(db='LabTracker')
AttributeError: 'MySQLdb' module has no attribute 'Connect' I looked through MySQLdb.py and the statement "Connect = connect = Connection" is right where I expected it to be.  I've also tried the same code replacing "Connect" with "Connection" and "connect", to no avail.  I'm trying to finish up a project which will involve installation on WinNT 4.0 (which is why I'm fiddling with Win2K; it's the closet thing I have to the NT 4 environment), so any help will be tremendously appreciated! Thanks in advance, John Hopkinsjohn@hopkinsit.com
--------------CE331CB0FA7FF8B594568D45-- From Jim.Vickroy@noaa.gov Mon Jul 16 21:25:17 2001 From: Jim.Vickroy@noaa.gov (Jim Vickroy) Date: Mon, 16 Jul 2001 14:25:17 -0600 Subject: [python-win32] com_error: (-2147467259, 'Unspecified error', None, None) Message-ID: <3B534DAD.CDBC25AA@noaa.gov> Hello, Could someone offer a suggestion about the source of the following error. >>> import win32com.client >>> el = win32com.client.Dispatch('EventsLog.Application') Traceback (innermost last): File "", line 1, in ? File "D:\Python20\win32com\client\__init__.py", line 94, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "D:\Python20\win32com\client\dynamic.py", line 80, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "D:\Python20\win32com\client\dynamic.py", line 71, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) com_error: (-2147467259, 'Unspecified error', None, None) >>> The specified service, 'EventsLog.Application', is running when this error arises. Thanks. From john@hopkinsit.com Tue Jul 17 06:32:25 2001 From: john@hopkinsit.com (John Hopkins) Date: Mon, 16 Jul 2001 22:32:25 -0700 Subject: [python-win32] Re: MySQLdb AttributeError Problem References: <006f01c10cef$6eae2c70$01000059@hopkinsmain> <3B534C9A.FC9A08E8@ActiveState.com> Message-ID: <007101c10e81$e09c1520$01000059@hopkinsmain> Thanks for the replies. I ended up de-installing everything (Python, MySQL, etc.) and re-installing. It works now, so I suspect the problem was that I had failed to re-install mxDateTime, a documented requirement for MySQLdb. Sorry to bother the lists for a boneheaded error ... John From jens.jorgensen@tallan.com Sat Jul 21 00:30:52 2001 From: jens.jorgensen@tallan.com (Jorgensen, Jens) Date: Fri, 20 Jul 2001 18:30:52 -0500 Subject: [python-win32] error installing 2.1.0 build 211 on Win2K AS? Message-ID: <3B58BF2C.6030308@tallan.com> Anyone else have any trouble installing ActivateState 2.1.0 build 211 in Win2K AS? A colleague here tried to install it and once it starts to do the actual copying of files and all it stops and goes to a new screen saying that an error occurred during the installation but doesn't say what kind of error. Is there perhaps some log file that's written? -- Jens B. Jorgensen jens.jorgensen@tallan.com From Jim Abrams Mon Jul 23 17:47:34 2001 From: Jim Abrams (Jim Abrams) Date: Mon, 23 Jul 2001 12:47:34 -0400 Subject: [python-win32] win32, ASP, ActivePython COM Help Message-ID: <3259233658.20010723124734@publishingresources.com> I've posted this to c.l.py to no avail, any ideas, however odd, might help. PythonWin 2.1 (#15, Apr 19 2001, 10:28:27) [MSC 32 bit (Intel)] on win32. Portions Copyright 1994-2001 Mark Hammond (MarkH@ActiveState.com) - see 'Help/About PythonWin' for further copyright information. >>> import win32com.client >>> pptc = win32com.client.Dispatch("Powerpoint.Application") >>> ppt = pptc.Presentations.Add(WithWindow=0) >>> slide = ppt.Slides.Add(1, 12) >>> shapes = slide.Shapes >>> shapes.AddOLEObject(ClassName=u'ShockwaveFlash.ShockwaveFlash.1') >>> pptc >>> ppt >>> slide >>> shapes >>> shapes.AddOLEObject >>> All is cool. But, try this same thing inside an ASP page... <%@LANGUAGE="Python"%> <% def w(o): Response.Write(Server.HTMLencode(repr(o)) + "
") import win32com.client pptc = win32com.client.Dispatch("Powerpoint.Application") w(pptc) ppt = pptc.Presentations.Add(WithWindow=0) w(ppt) slide = ppt.Slides.Add(1, 12) w(slide) shapes = slide.Shapes w(shapes) w(shapes.AddOLEObject) shapes.AddOLEObject(ClassName=u'ShockwaveFlash.ShockwaveFlash.1') w(shape) %> gets me: Python ActiveX Scripting Engine error '80020009' Traceback (innermost last): File "