ignoring keywords on func. call
Hi !
If I define 'f' like this
def f(a):
print a
then, the call with keywords
f(1, optional=2)
fails. I have to change 'f' to
def f(a, **kwrds):
print a
to ignore optional parameters.
BUT..
Q: Can you call 'f' with keywords that will be
ignored, without changing 'f's definition ?
I would like to avoid code like this:
k = {}
k['optional'] = 2
try:
f(1, **k)
except TypeError:
f(1)
Also, the problem is that I don't know if the TypeError
was caused by calling 'f' with keywords or somewhere
"inside" f.
You can also say that I need to specify optional parameters
on caller side (not called side).
BranoZ
.
Relevant Pages
- Re: def a((b,c,d),e):
... > ideas in there about argument passing. ... > that named keywords may be intermixed with positional keywords, ... - Put the default(s) before the positional arguments: ... Concerning default argument expressions, a neat feature would be to ... (comp.lang.python) - Re: Code Heuristics (#172)
... rescue case when exit unless and or not class module new def raise ... return KEYWORDS unless file ... # Assume that symbols are language items. ... # is just an example and not part of the actual submission ... (comp.lang.ruby) - Re: map/filter/reduce/lambda opinions and background unscientific mini-survey
... Why def instead of define? ... Because "easy to write" beats "instantly obvious to a beginner", if the word is used all the time and is easy to memorize. ... frequently used keywords in the language, so i think it's reasonable to keep them short. ... simple relationship between flow control keywords, meanings, and blocks of code, which would be broken if we moved to using "else if". ... (comp.lang.python) - Re: J2 0-2-6 is available
... > has too meanings: the first is to import a library and the second is to ... generic keywords like: by, having, per, via, extend (extend means ... predef. ... (comp.lang.python) - methods, methods override classes and scope
... I am trying to figure out how scope works with method in methods (or actually overriding). ... def parser.startElement ... # Process only links and the meta tag (including keywords) ... # Extract the meta content including keywords ... (comp.lang.ruby) |
|