By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,728 Members | 1,112 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,728 IT Pros & Developers. It's quick & easy.

Is it allowed to use function results as default arguments ?

P: n/a
hello,

I've a perfect working procedure,
at least as far I've tested it it works perfect.

But I was just experimenting with inspect,
and saw that the default argument was not parsed correctly.

So I wonder if this is allowed:

def Get_Relative_Path ( target, base=os.curdir ) :
...

As inspect returns the following:

(['target', 'base'], None, None, ('.',))

thanks,
Stef Mientki
Jul 28 '08 #1
Share this Question
Share on Google+
5 Replies

P: n/a
On Jul 28, 1:28*pm, Stef Mientki <stef.mien...@gmail.comwrote:
hello,

I've a perfect working procedure,
at least as far I've tested it it works perfect.

But I was just experimenting with inspect,
and saw that the default argument was not parsed correctly.

So I wonder if this is allowed:

def Get_Relative_Path ( target, base=os.curdir ) :
* ...

As inspect returns the following:

(['target', 'base'], None, None, ('.',))

thanks,
Stef Mientki
os.curdir is '.' on many platforms. What did you expect inspect to
show?

|>>import os
|>>os.curdir
'.'
Jul 28 '08 #2

P: n/a
On Jul 28, 3:28*pm, Stef Mientki <stef.mien...@gmail.comwrote:
hello,

I've a perfect working procedure,
at least as far I've tested it it works perfect.

But I was just experimenting with inspect,
and saw that the default argument was not parsed correctly.

So I wonder if this is allowed:

def Get_Relative_Path ( target, base=os.curdir ) :
Did you perhaps mean to say def Get_Relative_Path(target,
base=os.getcwd()):
* ...

As inspect returns the following:

(['target', 'base'], None, None, ('.',))

thanks,
Stef Mientki
Jul 29 '08 #3

P: n/a
Well, others have answered the question, but I thought I'd throw in
that it would be more pythonic to do something like:

def Get_Relative_Path(target, base = None):
if base is None:
base = os.curdir
...

Jul 30 '08 #4

P: n/a
"fred.haab" <fr*******@gmail.comwrites:
Well, others have answered the question, but I thought I'd throw in
that it would be more pythonic to do something like:

def Get_Relative_Path(target, base = None):
if base is None:
base = os.curdir
...
Even more Pythonic would be to name the function by the style guide
(PEP 8):

def get_relative_path(target, base=None):
if base is None:
base = os.curdir
# …

--
\ “If trees could scream, would we be so cavalier about cutting |
`\ them down? We might, if they screamed all the time, for no good |
_o__) reason.” —Jack Handey |
Ben Finney
Jul 30 '08 #5

P: n/a


fred.haab wrote:
Well, others have answered the question, but I thought I'd throw in
that it would be more pythonic to do something like:

def Get_Relative_Path(target, base = None):
if base is None:
base = os.curdir
...
Since os.curdir is a constant, this is nonesensical. One only needs the
dummy default when one wants an expression re-evaluated with each call.

Jul 30 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.