In defence of the two-namespace rule

Aahz Maruch aahz at netcom.com
Fri Jan 21 10:38:55 EST 2000


In article <m3n1q0fzg7.fsf at greebo.nodomain.de>,
Bernhard Herzog  <herzog at online.de> wrote:
>
>To reuse one of Edward's examples:
>
>  def filename(*fragments, **, root=os.getcwd()):
>      """Resolves relative paths."""
>      # Assume os.path.join joins arbitrarily many fragments.
>      return apply(os.path.join, (root,) + fragments)
>
>IMO, the root=os.getcwd() should be moved outside the argument list.
>It's assigned at definition time and can't be changed in any way when
>the function is called, so it's not an argument. Something like this
>would be better:
>
>  def filename(*fragments), root=os.getcwd():
>      """Resolves relative paths."""
>      # Assume os.path.join joins arbitrarily many fragments.
>      return apply(os.path.join, (root,) + fragments)

I think both are horrid.  Why not simply

  root = os.getcwd()
  def filename(*fragments):
      """Resolves relative paths."""
      # Assume os.path.join joins arbitrarily many fragments.
      return apply(os.path.join, (root,) + fragments)

Of course, this is broken code, anyway.  The current working directory
can change any time, and this code should therefore be

  def filename(*fragments):
      """Resolves relative paths."""
      # Assume os.path.join joins arbitrarily many fragments.
      root = os.getcwd()
      return apply(os.path.join, (root,) + fragments)
--
                      --- Aahz (@netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

Have a *HAPPY* day!!!!!!!!!!



More information about the Python-list mailing list