473,386 Members | 1,668 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,386 software developers and data experts.

default values of function parameters

Alan Isaac wrote:
Default parameter values are
evaluated once when the function definition is
executed. Where are they stored? ... Where is this documented?


Forgive any poor phrasing: I'm not a computer science type.
At http://www.network-theory.co.uk/docs/pytut/tut_26.html we read:
"The execution of a function introduces a new symbol table
used for the local variables of the function. More precisely,
all variable assignments in a function store the value in the local
symbol table; whereas variable references first look in the local
symbol table, then in the global symbol table, and then in the table of
built-in names."

But the default values of function parameters seem rather like a static
attributes of a class.
Is that a good way to think of them?
If so, are they somehow accessible?
How? Under what name?

Thanks,
Alan Isaac

Jul 19 '05 #1
1 1828

"David Isaac" <ai*****@verizon.net> wrote in message
news:piPoe.8518$ld3.1868@trnddc04...
But the default values of function parameters seem rather like a static
attributes of a class.
Is that a good way to think of them?
If you think of a function as defining a subclass of execution instances,
with __init__ inherited from the superclass, then that is a possible way to
think of them. Goodness depends on your meaning of goodness ;-). Does it
help you write and use Python functions acurately?
If so, are they somehow accessible?
How? Under what name?


This is implementation specific. For CPython, the interactive interpreter
is your friend. Learn to use it!
def f(): pass .... dir(f)

['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__get__',
'__ge
tattribute__', '__hash__', '__init__', '__name__', '__new__', '__reduce__',
'__r
epr__', '__setattr__', '__str__', 'func_closure', 'func_code',
'func_defaults',
'func_dict', 'func_doc', 'func_globals', 'func_name']

Now give f some parameters with defaults and print f.func_defaults.

Terry J. Reedy

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

46
by: J.R. | last post by:
Hi folks, The python can only support passing value in function call (right?), I'm wondering how to effectively pass a large parameter, such as a large list or dictionary? It could achieved...
12
by: earl | last post by:
class temp { public: temp(); foo(char, char, char*); private: char matrix; }; temp::foo(char p, char o, char m = matrix )
18
by: Matt | last post by:
I try to compare the default constructor in Java and C++. In C++, a default constructor has one of the two meansings 1) a constructor has ZERO parameter Student() { //etc... } 2) a...
2
by: Vic Y | last post by:
Hi, I am trying to call a user defined function(UDF) from a stored proc, using a default parameter in the called UDF (e.g. @bid_price_type int = 0 ). However the calling stored proc complains...
8
by: cody | last post by:
Why doesn't C# allow default parameters for methods? An argument against I hear often is that the default parameters would have to be hardbaken into the assembly, but why? The Jit can take care of...
5
by: Imran Aziz | last post by:
Hello All, I am new to C# , how can I delare parameters to a function as optional, and also how are default values assigned ? consider the function public String myFunc(String thisisOptional,...
8
by: **Developer** | last post by:
Been reading some of the Marshal doc and am a little confused. Anyway, I've been using the following and it works OK. Public Declare Auto Function SHGetFolderPath Lib "shell32.dll" (ByVal hWnd...
21
by: Dmitry Anikin | last post by:
I mean, it's very convenient when default parameters can be in any position, like def a_func(x = 2, y = 1, z): ... (that defaults must go last is really a C++ quirk which is needed for overload...
14
by: cody | last post by:
I got a similar idea a couple of months ago, but now this one will require no change to the clr, is relatively easy to implement and would be a great addition to C# 3.0 :) so here we go.. To...
7
by: jamesclose | last post by:
My problem is this (apologies if this is a little long ... hang in there): I can define a function in VB.NET with optional parameters that wraps a SQL procedure: Sub Test(Optional ByVal Arg1...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
0
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,...
0
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...

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.