[Tutor] Calling a Method with a Reserved Name

Eric Brunson brunson at brunson.com
Wed Oct 24 15:36:55 CEST 2007


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
function require() {
print( "Hello World" );
}
?>

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 at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   




More information about the Tutor mailing list