473,799 Members | 2,907 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,$arre f) = @_;
# 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 3511
Wijaya Edward wrote:
I wonder how can that be done in Python.
def myfunc(plain_va r, 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_va r, 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_va r, 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_va r, 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************* *************** *************** @python.org on behalf of Steve Holden
Sent: Tue 10/3/2006 8:08 PM
To: py*********@pyt hon.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
2348
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 $arr=array(); (syntax err) 2) global $arr; in "main", the var isn't global 3) global $arr; in function, the array is cleared each time
26
9633
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
5094
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 are not at all. If you are doing *array", then you have to use only integer values for array index, as it was since ALGOL.
5
3527
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 accepts a void* key argument, and uses the functions above to store this argument. It returns something (linked to the key) that the caller can store a value in. The actual key argument is always of the same pointer type (as seen in the caller,...
9
2319
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 function that was included in all pages that took an SQL query and returned a disconnected recordset. This meant that data access could be achieved in a single line. I would like to do something similar in ASP.NET. I know I could just duplicate...
4
13411
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 be read and the string representation of the byte array has to be converted back to the original byte array and converted back to the original string - confused yet? in psuedo
29
2334
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) so after that point whenever you use X it gets replaced by (*X)
3
3380
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 doSomething({variable1:"blabla",variable2:"blabla"}); how would function doSomething be written for this to work. I would also like the hash to be optional and the variables in the
8
5431
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 a function which maps a tuple of 25 integers into 1 integer with good hashing properties. Does anybody know such a thing?
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9538
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10249
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10219
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6804
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4138
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.