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 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
'.'
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
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
...
"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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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>...
|
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. ...
|
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...
|
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
|
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'...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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,...
|
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...
| |