Hi All, I'm using Python inside a Windows Script Component (.wsc). I instantiate the WSC and call the code from classic ASP using VBscript. Now I'm running into a couple of problems:
The standard ASP objects seem not to be available to Python in the WSC, even though the WSC has the implements ASP tag: <implements type="ASP" id="ASP"/> I have a workaround for this; I pass an object to the WSC that has all of the standard IIS objects like request, response, session etc. as a property. Using that I -am- able to access the standard IIS objects, but it's obviously not an ideal solution. The code looks like this: def openGM(superObject): """places all of the projects and ASP objects into a global context so we can use it from inside the entire wsc.""" global request, response, application, session, translate, debug, usr, datatyping, dal, server request = superObject.Request response = superObject.Response application = superObject.Application session = superObject.Session ...etc The second problem I'm running into is debugging. Because I'm running the code from inside a WSC, which is in fact an active script component, the ASP page calling the WSC doesn't give me a descriptive error when there's something wrong in the WSC code. When developing in VBscript (at least locally), errors in the WSC will trigger Visual Studio, or another external debugger and allow me to debug the WSC code. PyScript doesn't seem to trigger anything. I have seen the axdebug module in the win32 extentions, but I have no idea how to implement this. Is it supposed to work out of the box, or is there something I need to do, to enable debugging from inside a WSC ? I have also tried importing win32traceutil, but that only seems to work for stdout. If I use the Python print() command from my WSC, the text will show up in the trace collector window, but errors don't. I was under the impression that both stdout and stderr were redirected to the trace collector? I have also seen suggstions around the Internet to use the --debug option when registering a component, but this is a script-component, and I use it exclusively without registration, using the getObject() function like so: set pythonwsc = GetObject("script:"&Server.MapPath("/components/python.wsc")) Does anyone perhaps have any tips or suggestions I might use to be able to debug in such a situation? The last problem I have, is a very strange one. The module I'm re-writing in Python is a translation module. What it does is read a bunch of XML data into a few dictionaries. It then writes those dictionaries (one for each supported language) into a file using Python's "shelve". This all works fine. I have a LoadData() function that checks if there already is a shelve file, if not it will load the XML (which is always present) and create the shelve file. If the file already exists, it wil just load the file and use the dictionaries inside, pretty simple. I have a global dictionary simply called "d" in my code, and after I fill or load it, it is available. Then I call the function to give me a translation for one of the dictionary keys, and all of a sudden "d" is empty. I have tried defining d outside of all of the functions in the WSC using d = {}, I have also tried defining d at the moment data is loaded or created using the gloabal keyword; "global d". Both methods didn't work. The workaround I have is to create a new global variable in the function that loads the dictionary and assigning d to that. Here's what that looks like: def loadDataFromDAT(filepath): response.write("Load data from .DAT file") translation_db = shelve.open(filepath) d = translation_db[str(usr.var("lcid"))] #response.write("<br/>After loading data: " + str(d.keys())) global currentDictionary currentDictionary = d The strange thing is that d has values in this function, but when I call my "label()" function, which looks up a value for a key in the dictionary, it no longer has values, even though it is defined in another function as a global, or defined outside all of the functions (making it a global variable). If I then use "currentDictionary", it DOES have values. So the question is, what is the best way in a WSC to create a global variable, that works across functions inside the WSC? Thanks a lot for any answers or leads you guys can give me. The internet isn't exactly littered with information about Pyscrpt in WSC's I'm afraid, so I hope someone can shed some light on this. Kind regards, Erik
_______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32