question about functions

C

chris patton

Hi everyone.

I have a question about passing arguments to python functions. Is there
any way to make this job act like Perl?

sub my_funk {

print "the first argument: $_[0]\n";
print "the second argument: $_[1]\n"; }

In other words, can I call the arguments from a list?
 
J

James Stroud

Just pass a list. E.g.:

# start of ascript

def my_funk(alist):
print "the first argument: %s" % alist[1]
print "the second argument: %s" % alist[2]

mylist = ['wuzzup,','g?']

my_funk(mylist)

# end of ascript


Here is the output you expect:

the first argument: wuzzup,
the second argument: g?

Hi everyone.

I have a question about passing arguments to python functions. Is there
any way to make this job act like Perl?

sub my_funk {

print "the first argument: $_[0]\n";
print "the second argument: $_[1]\n"; }

In other words, can I call the arguments from a list?

--
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
 
J

James Stroud

Oops, I messed up the indices on the previous post.
Also, maybe you are thinking a bit more perlish:

# start of ascript

def my_funk(*alist):
print "the first argument: %s" % alist[0]
print "the second argument: %s" % alist[1]

my_funk('wuzzup,','g?')

# end of ascript

Hi everyone.

I have a question about passing arguments to python functions. Is there
any way to make this job act like Perl?

sub my_funk {

print "the first argument: $_[0]\n";
print "the second argument: $_[1]\n"; }

In other words, can I call the arguments from a list?

--
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
 
H

Heiko Wundram

Am Freitag, 15. April 2005 06:44 schrieb chris patton:
In other words, can I call the arguments from a list?
Yes.
... print args[0]
... print args[1]
...this is
a test

Read up on positional and keyword arguments (the latter are something that'd
make me choose python over anything else instantly) in the Python tutorial
and documentation.

--
--- Heiko.
listening to: Pearl Jam - Given To Fly
see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBCX0tWf0bpgh6uVAMRAvQyAJ9OjvkkD9i78tS7JDqU48cnKfaqdACeOEUx
OlRAXtd56fAlK4FAHmm0MLE=
=7tt0
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,234
Messages
2,571,180
Members
47,812
Latest member
Robi2

Latest Threads

Top