Perl and Python (Re: [prog] Re: [Techtalk] How to write web proxy in Python?)

Mary mary-linuxchix at puzzling.org
Fri Jan 10 11:11:09 EST 2003


On Thu, Jan 09, 2003, sherzodr at ultracgis.com wrote:
> I'm not a Python guy, but I wanted to comment to the message really quick.
> Perl5 supports OO interface as well, which wasn't mentioned.

Yup, I was aware of this.

> # Usage: send_email(subject=> "Hello World", message=> "This is from Perl");
> send_email {
>    my %args = (
> 	to 	=> 'sherzodr at cpan.org',
> 	from 	=> 'Geek at geeks.com',
> 	subject => '[No Subject],
> 	message => '***EMPTY MESSAGE***',
>  	@_,
>   );
> 
> Since I'm not sure about Python, was woundering how does Python deal
> with function arguments.

To write a function comparable with your method:

the function definition is:

# note that indentation is compulsory and meaningful in Python

def send_email(to, from, subject, message):
        # code would go here, but I'll just put pass, which tells Python
        # to do nothing
        pass

# this is me calling the function
send_email('sherzodr at cpan.org', 'Geek at geeks.com', '[No Subject]',
                '***EMPTY MESSAGE***')

# by default, that matches the arguments with their names in order, and 
# don't need to do it explicitly, but I could:

send_email(to = 'sherzodr at cpan.org',
        from = 'Geek at geeks.com',
        subject = '[No Subject]'
        message =  '[No Subject]')

It's the example of naming the arguments in the function definition, and
being able to call it and having it automatically match the names up
without having to explicitly manipulate a variable like @_ that is
unlike Perl and more like C, Java and C++.

-Mary



More information about the Programming mailing list