473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Howto pass Array/Hash into Function


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
6 3489
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
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
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
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Bob | last post by:
I've tried everything; and I can't seem to get past this VERY (seemingly) simply problem. I want to work with an array variable within a function(s). I can't get it to work; if I: 1) global...
26
by: JGH | last post by:
How can I check if a key is defined in an associative array? var users = new array(); users = "Joe Blow"; users = "John Doe"; users = "Jane Doe"; function isUser (userID) { if (?????)
47
by: VK | last post by:
Or why I just did myArray = "Computers" but myArray.length is showing 0. What a hey? There is a new trend to treat arrays and hashes as they were some variations of the same thing. But they...
5
by: Stijn van Dongen | last post by:
A question about void*. I have a hash library where the hash create function accepts functions unsigned (*hash)(const void *a) int (*cmp) (const void *a, const void *b) The insert function...
9
by: Alan Silver | last post by:
Hello, I'm a bit surprised at the amount of boilerplate code required to do standard data access in .NET and was looking for a way to improve matters. In Classic ASP, I used to have a common...
4
by: David Bargna | last post by:
Hi I have a problem, I have a string which needs to be converted to a byte array, then have the string representation of this array stored in an AD attribute. This string attribute then has to...
29
by: Ancient_Hacker | last post by:
It sure would be nice if I could have a macro that add a level of indirection to its argument. So if I write: AddIndirection( X ) The macro AddIndirection will do: #define X (*X) ...
3
by: giloosh | last post by:
can i pass a hash as a function parameter. ive seen it been used before but i can't figure out how to do it. i would like to call a function like this for example ...
8
by: Helmut Jarausch | last post by:
Hi, I need to hash arrays of integers (from the hash module). So, I have to derive from array and supply a __hash__ method. But how to hash an array (of fixed length, say 25)? What I need is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.