473,406 Members | 2,293 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,406 software developers and data experts.

Is it allowed to use function results as default arguments ?

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
5 912
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
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
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
"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


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Nick Coghlan | last post by:
Time for another random syntax idea. . . So, I was tinkering in the interactive interpreter, and came up with the following one-size-fits-most default argument hack: Py> x = 1 Py> def...
11
by: BRG | last post by:
I know that default template arguments cannot be used in function templates but are default function parameters legal? That is, is this: ---------------------------------- #include <functional>...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
7
by: K. Jansma | last post by:
Hi, given the following example class class Test: def f(self,a, L=): L.append(a) return L and the following statements
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
4
by: Lighter | last post by:
Why is template function not allowed to have defaut arguments? We know that class template is allowed to have default arguments in C++ standard, why is template function not? I can't think out...
7
by: andrewfsears | last post by:
I have a question: I was wondering if it is possible to simulate the multiple constructors, like in Java (yes, I know that the languages are completely different)? Let's say that I have a class...
0
by: Guilherme Polo | last post by:
On Mon, Jul 28, 2008 at 5:28 PM, Stef Mientki <stef.mientki@gmail.comwrote: Are you referring to the last item in the tuple above ? It is merely listing the default values, it is not associating...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.