Re: [Tutor] using dynamic import statements
On Mon, Jul 9, 2012 at 6:40 AM, Chris Hare ch...@labr.net wrote: Here is what I want to do: I have a bunch of modules to import. instead of duplicating a lot of code for each import, I want to do something like this: importList = [ sys, os, imp, stat, re, webbrowser, Image, StringIO, shutil, datetime ] for object in importList: try: if debug == ON: print Importing module %s % (object) exec( import + object) except ImportError as error: print %s %s requires the Python %s library. % ( appName, str(appVersion), object ) print An error occurred when attempting to load the library. The error was '%s'. % ( error ) exit() Everything appears to run okay, however, when the first piece of code that relies upon one of these imported modules is executed, I get an error: Traceback (most recent call last): File a.py, line 122, in module imp.load_module(object,fp,pathName,description) File ./Modules/functions.py, line 133, in module def special_match(strg, search=re.compile(r'[^a-zA-Z0-9\.\ \-\#\$\*\@\!\%\^\]').search): NameError: name 're' is not defined Is is possible to do what I am trying to do, or am I doing something wrong? Thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Hi, How about using import imp http://docs.python.org/library/imp.html calling run time modules as per your need. thank you ankur. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Query with SOAP request generation, which other modules can be used.
Dear Pythoneers, We want to butile the SOAP request request in below manner. - In header we want to pass the wsse auth part and custom transref section and both has different xmlns. soapenv:Envelope xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/; xmlns:com=http://some.xmlns.org/.1.0/Common.xsd; xmlns:bil= http://some.xmlns.org/Schema/Billing/1.0/Billing.xsd; soapenv:Header com:TransRef com:SourceSystemIdPORTAL/com:SourceSystemId com:TxID123456/com:TxID com:BID123456/com:BID /com:TranRef wsse:Security xmlns:wsse= http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd wsse:UsernameToken wsu:Id=UsernameToken-1 xmlns:wsu= http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd wsse:Usernameuser/wsse:Username wsse:Passwordpass/wsse:Password /wsse:UsernameToken /wsse:Security /soapenv:Header soapenv:Body bil:getBill bil:ID187000/bil:ID /bil:getBill /soapenv:Body /soapenv:Envelope Currently we are using pysimplesoap ( http://code.google.com/p/pysimplesoap/) module for this. The current python code is attached. But we are not able to pass the custom xmlns ( for bil and for com - the very first line ) with pysimplesoap module. *Any idea which other module we have to explore for generating the SOAP request like above.* Thank You, Ankur. from pysimplesoap.client import SoapClient import sys,traceback client = SoapClient( location=http://www.abc.com/ABC/Billing;, action = http://www.abc.org/Service/getBill;, namespace=http://www.abc.org/Service/Billing.wsdl;, trace=True) client['wsse:Security'] = { 'wsse:UsernameToken': { 'wsse:Username': 'username', 'wsse:Password': 'password', } } client['com:TransRef'] = { 'com:SystemId': 'PORTAL', 'com:TxID': '20012001161378998', 'com:BID': '123456789' } try: response = client.getBill(AccountID=123456) print response except: errortrace = ''.join(traceback.format_exception(*sys.exc_info())) print(Unexpected error: %s % (errortrace,)) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor