By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,957 Members | 1,960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,957 IT Pros & Developers. It's quick & easy.

Howto pass Array/Hash into Function

P: n/a

Hi,

How can I pass Array, Hash, and a plain variable
in to a function at the same time.

I come from Perl. Where as you probably know
it is done like this:

sub myfunc {

my ($plain_var, $hash_ref,$arref) = @_;
# Do sth with those variables

return;
}

I wonder how can that be done in Python.

Regards,
Edward WIJAYA
SINGAPORE

------------ Institute For Infocomm Research - Disclaimer -------------
This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you.
--------------------------------------------------------
Oct 3 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Wijaya Edward wrote:
I wonder how can that be done in Python.
def myfunc(plain_var, hash_ref, arref):
# Do sth with those variables
return

Regards,
Jordan

Oct 3 '06 #2

P: n/a
MonkeeSage wrote:
Wijaya Edward wrote:
>I wonder how can that be done in Python.

def myfunc(plain_var, hash_ref, arref):
# Do sth with those variables
return
At the risk of being a jerk (sorry, I'm really just curious):
Why isn't that obvious?

wildemar (sorry)
Oct 3 '06 #3

P: n/a
Wildemar Wildenburger wrote:
MonkeeSage wrote:
Wijaya Edward wrote:
I wonder how can that be done in Python.
def myfunc(plain_var, hash_ref, arref):
# Do sth with those variables
return

At the risk of being a jerk (sorry, I'm really just curious):
Why isn't that obvious?

wildemar (sorry)
I wondered that too and wasn't even going to answer, but then I thought
mabye the question was meant to be more general, like "what is the
syntax for passing objects to functions in python?"

Regards,
Jordan

Oct 3 '06 #4

P: n/a
MonkeeSage wrote:
Wildemar Wildenburger wrote:
>>MonkeeSage wrote:
>>>Wijaya Edward wrote:

I wonder how can that be done in Python.

def myfunc(plain_var, hash_ref, arref):
# Do sth with those variables
return

At the risk of being a jerk (sorry, I'm really just curious):
Why isn't that obvious?

wildemar (sorry)


I wondered that too and wasn't even going to answer, but then I thought
mabye the question was meant to be more general, like "what is the
syntax for passing objects to functions in python?"
It wouldn't be obvious to someone who learned Perl as their first
programming language because Perl chose to ignore the otherwise almost
universal convention that formal parameters determine the arguments that
a function or procedure can be calles with.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Oct 3 '06 #5

P: n/a

Thanks for your understanding Steve.

Furthermore, my related concern
is how does Python actually deal with 'reference' in Perl.
But now, it is clear to me now that Python simply
treats them as object.

Regards,
Edward WIJAYA
SINGAPORE

________________________________

From: py*******************************************@pyth on.org on behalf of Steve Holden
Sent: Tue 10/3/2006 8:08 PM
To: py*********@python.org
Subject: Re: Howto pass Array/Hash into Function


It wouldn't be obvious to someone who learned Perl as their first
programming language because Perl chose to ignore the otherwise almost
universal convention that formal parameters determine the arguments that
a function or procedure can be calles with.

regards
Steve


------------ Institute For Infocomm Research - Disclaimer -------------
This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you.
--------------------------------------------------------
Oct 3 '06 #6

P: n/a
Wijaya Edward wrote:
Thanks for your understanding Steve.

Furthermore, my related concern
is how does Python actually deal with 'reference' in Perl.
But now, it is clear to me now that Python simply treats
them as object.
sounds like you really need to reset your brain:

http://effbot.org/zone/python-objects.htm

</F>

Oct 3 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.