LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-24-2004, 01:29 PM   #1
johnMG
Member
 
Registered: Jul 2003
Location: CT, USA
Distribution: Debian Sarge (server), Etch (work/home)
Posts: 601

Rep: Reputation: 32
Python function arguments are dictionaries?


I'm learning Python and reading the diveintopython book (which is *excellent* I might add).

Anyhow, on page 38, when referring to function argument(s)(?) the authors mention, "This looks totally whacked until you realize that arguments are simply a dictionary."

Could someone please explain to me what that means? Is each individual argument a dictionary under the covers, or is the entire group of args a dictionary?

I'm guessing that they're talking about how function args are dealt with internal to the Python interpreter, but any insight on this subject is appreciated.

The example the book uses is

def info(object, spacing=10, collapse=1):
[...snip...]

and then calling it like so:

info(odbchelper)
info(odbchelper, 12)
info(odbchelper, collapse=0)
info(spacing=15, object=odbchelper)

Last edited by johnMG; 07-24-2004 at 01:33 PM.
 
Old 07-24-2004, 06:29 PM   #2
NeoAndersn007
Member
 
Registered: Jul 2004
Distribution: Debian
Posts: 72

Rep: Reputation: 15
Ok I dont have the book but my best guest is that the author is saying that arguments like for example
def DoStuff(Stuff="being weird", Do="Whenever", AnotherArg)
are like dictionarys, they have a key and a value and you can change them in any order by using the Variable and an equals sign. So that
Code:
DoStuff("being weird", AnotherArg="other random arg", Do="Now")
is the same as
Code:
Args = {
    Stuff:"being weird",
    AnotherArg:"other random arg",
    Do:"Now"}
DoStuff(Args)
You don't really need to understand it its just trying to give you a better (or worse) perspective of using Arguments

EDIT: also note that when using the Python C API all the arguments are passed as tuples

Last edited by NeoAndersn007; 08-14-2004 at 12:09 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass structure as function arguments ssg14j Programming 2 08-20-2005 09:59 PM
Accessing nested dictionaries in Python DiagonalArg Programming 13 08-20-2005 08:37 PM
python os.system arguments randomx Programming 2 03-03-2005 03:54 PM
C Function Arguments jpbarto Programming 6 04-23-2004 01:59 PM
Function accept() and its arguments. krajzega Programming 1 01-20-2004 01:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration