Is it allowed to use function results as default arguments ?

Ben Finney bignose+hates-spam at benfinney.id.au
Wed Jul 30 06:10:17 CEST 2008


"fred.haab" <fred.haab at gmail.com> writes:

> 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



More information about the Python-list mailing list