Re: [Tutor] Calling a Method with a Reserved Name
On 10/24/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > Alex Ezell wrote: > > ># TODO figure out how to call this soap method with reserved name > >self.call_response = self.soap.import(self.soap_auth, > > file_name, import_groups, soap_flags) > > > I tried to replace the import() call with these two lines: > > importFunc = getattr(self.soap, 'import') > > self.call_response = self.soap.importFunc(self.soap_auth, file_name, > > import_groups, soap_flags) > > this should be > self.call_response = importFunc(self.soap_auth, file_name, > import_groups, soap_flags) > > importFunc *is* the function you want to call, it is not an attribute of > self.soap. > > Kent Awesome. I knew I had just been looking at it for too long. Thanks so much, Kent! Maybe one day, I will help you with something. ;) /alex ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calling a Method with a Reserved Name
Alex Ezell wrote: ># TODO figure out how to call this soap method with reserved name >self.call_response = self.soap.import(self.soap_auth, > file_name, import_groups, soap_flags) > I tried to replace the import() call with these two lines: > importFunc = getattr(self.soap, 'import') > self.call_response = self.soap.importFunc(self.soap_auth, file_name, > import_groups, soap_flags) this should be self.call_response = importFunc(self.soap_auth, file_name, import_groups, soap_flags) importFunc *is* the function you want to call, it is not an attribute of self.soap. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calling a Method with a Reserved Name
Oops, meant to send to the list. Sorry, Kent. > > > >>> I am working on building a SOAP client. Unfortunately, one of the > > > >>> methods the SOAP server provides is named "import." The SOAP server is > > > >>> written in PHP. > > > >>> > > > >>> So, my problem is that Python really doesn't like me using the word > > > >>> "import" to call the SOAP method. The call should look something like > > > >>> this: > > > >>> > > > >>> self.call_response = self.soap.import(self.soap_auth, file_name, > > > >>> import_groups, soap_flags) > > > >>> > > > >>> Is there any way to call this method despite it's name being a > > > >>> reserved word. > > > >> You could try introspection: > > > >> > > > >> importFunc = getattr(self.soap, 'import') > > > >> self.call_response = importFunc(self.soap_auth, file_name, > > > >> import_groups, soap_flags) > > > > > > > > Thanks Kent. I tried it and it seem like importFunc is now something > > > > like 'import.__str__'. I could maybe do some string operations to just > > > > get import out of that, but is there something I could do with > > > > getattr() for that reference to come back the way I need. > > > > > > Hmm, with a quick look at the code for SOAPpy (v 0.11.6) I don't see why > > > the getattr() method would not work. Can you show the code you tried and > > > why you think the result was a string? > > > > > > BTW pulling 'import' out of the string won't help; you need the import > > > *function*. > > > > Got ya on the string bit. That was actually my fault. I think I am the > > victim of my own poorly written exception handling method. Or at > > least, I can't correctly read the errors that it tells me. :) > > > > The introspection bit you offered seems to work fine. The error is now > > within the call to the SOAP server. > > > > Sorry for getting everyone confused. I'm off to ask my fellow > > developer if the SOAP server really does what it says does since she > > wrote it :) > > > > /alex Heh, I am still having problems with this. This is the whole method: def importer(self, file_name, import_groups, import_flags): soap_flags = self.dict_to_key_value(import_flags) try: # TODO figure out how to call this soap method with reserved name self.call_response = self.soap.import(self.soap_auth, file_name, import_groups, soap_flags) except Exception, e: method_name = sys._getframe().f_code.co_name method_args = '(%s,%s,%s)' %(file_name,str(import_groups),str(import_flags)) self.handle_exception(method_name + method_args,e) raise return self.call_response I tried to replace the import() call with these two lines: importFunc = getattr(self.soap, 'import') self.call_response = self.soap.importFunc(self.soap_auth, file_name, import_groups, soap_flags) and this was the error: AttributeError: importFunc module body in sync_members.py at line 143 function main in sync_members.py at line 138 function sforce_to_membersin sync_members.py at line 80 function do_importin sync_members.py at line 70 function importer in emma_ws.py at line 84 function __getattr__ in WSDL.py at line 96 Thanks again for working with me this far. I am certainly on the very precipitous edge of my Python "knowledge." /alex ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calling a Method with a Reserved Name
bob gailer wrote: > Alex Ezell wrote: > >> I am working on building a SOAP client. Unfortunately, one of the >> methods the SOAP server provides is named "import." The SOAP server is >> written in PHP. >> >> So, my problem is that Python really doesn't like me using the word >> "import" to call the SOAP method. >> > This seems unfortunate and too restrictive, to not allow keywords to be > used for other purposes, when the context makes it clear that its use is > not as a keyword. > Python isn't the only language, try compiling this with a C compiler: int main(){ int char = 1; } test.c:3: error: expected identifier or ‘(’ before ‘=’ token or a C++ compiler: test.C:3: error: expected unqualified-id before ‘=’ token Or running this through a PHP interpreter: PHP Parse error: syntax error, unexpected T_REQUIRE, expecting T_STRING in test.php on line 2 Oh, well. :-) > PL/I works that way: one may code > if if = then then > then = else > else > else = if > > Not that that is recommended coding style. > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calling a Method with a Reserved Name
Alex Ezell wrote: > On 10/24/07, Kent Johnson <[EMAIL PROTECTED]> wrote: >> Alex Ezell wrote: >>> I am working on building a SOAP client. Unfortunately, one of the >>> methods the SOAP server provides is named "import." The SOAP server is >>> written in PHP. >>> >>> So, my problem is that Python really doesn't like me using the word >>> "import" to call the SOAP method. The call should look something like >>> this: >>> >>> self.call_response = self.soap.import(self.soap_auth, file_name, >>> import_groups, soap_flags) >>> >>> Is there any way to call this method despite it's name being a reserved >>> word. >> You could try introspection: >> >> importFunc = getattr(self.soap, 'import') >> self.call_response = importFunc(self.soap_auth, file_name, >> import_groups, soap_flags) > > Thanks Kent. I tried it and it seem like importFunc is now something > like 'import.__str__'. I could maybe do some string operations to just > get import out of that, but is there something I could do with > getattr() for that reference to come back the way I need. Hmm, with a quick look at the code for SOAPpy (v 0.11.6) I don't see why the getattr() method would not work. Can you show the code you tried and why you think the result was a string? BTW pulling 'import' out of the string won't help; you need the import *function*. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calling a Method with a Reserved Name
Alex Ezell wrote: >> You could try introspection: >> >> importFunc = getattr(self.soap, 'import') >> self.call_response = importFunc(self.soap_auth, file_name, >> import_groups, soap_flags) > > Thanks Kent. I tried it and it seem like importFunc is now something > like 'import.__str__'. I could maybe do some string operations to just > get import out of that, but is there something I could do with > getattr() for that reference to come back the way I need. I guess you will have to dig into the implementation of the client a bit and find out what self.soap.import does and duplicate that somehow. What client code are you using? I would look for a __getattr__ method in the class implementing self.soap, for starters. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calling a Method with a Reserved Name
Alex Ezell wrote: > I am working on building a SOAP client. Unfortunately, one of the > methods the SOAP server provides is named "import." The SOAP server is > written in PHP. > > So, my problem is that Python really doesn't like me using the word > "import" to call the SOAP method. This seems unfortunate and too restrictive, to not allow keywords to be used for other purposes, when the context makes it clear that its use is not as a keyword. PL/I works that way: one may code if if = then then then = else else else = if Not that that is recommended coding style. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calling a Method with a Reserved Name
On 10/24/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > Alex Ezell wrote: > > I am working on building a SOAP client. Unfortunately, one of the > > methods the SOAP server provides is named "import." The SOAP server is > > written in PHP. > > > > So, my problem is that Python really doesn't like me using the word > > "import" to call the SOAP method. The call should look something like > > this: > > > > self.call_response = self.soap.import(self.soap_auth, file_name, > > import_groups, soap_flags) > > > > Is there any way to call this method despite it's name being a reserved > > word. > > You could try introspection: > > importFunc = getattr(self.soap, 'import') > self.call_response = importFunc(self.soap_auth, file_name, > import_groups, soap_flags) Thanks Kent. I tried it and it seem like importFunc is now something like 'import.__str__'. I could maybe do some string operations to just get import out of that, but is there something I could do with getattr() for that reference to come back the way I need. Thanks again. /alex ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calling a Method with a Reserved Name
Alex Ezell wrote: > I am working on building a SOAP client. Unfortunately, one of the > methods the SOAP server provides is named "import." The SOAP server is > written in PHP. > > So, my problem is that Python really doesn't like me using the word > "import" to call the SOAP method. The call should look something like > this: > > self.call_response = self.soap.import(self.soap_auth, file_name, > import_groups, soap_flags) > > Is there any way to call this method despite it's name being a reserved word. You could try introspection: importFunc = getattr(self.soap, 'import') self.call_response = importFunc(self.soap_auth, file_name, import_groups, soap_flags) I don't know if this will work here or not, I assume self.soap is already doing some attribute magic. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Calling a Method with a Reserved Name
I am working on building a SOAP client. Unfortunately, one of the methods the SOAP server provides is named "import." The SOAP server is written in PHP. So, my problem is that Python really doesn't like me using the word "import" to call the SOAP method. The call should look something like this: self.call_response = self.soap.import(self.soap_auth, file_name, import_groups, soap_flags) Is there any way to call this method despite it's name being a reserved word. /alex ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor