[prev in list] [next in list] [prev in thread] [next in thread]
List: python-list
Subject: Re: [path-PEP] Path inherits from basestring again
From: Reinhold Birkenfeld <reinhold-birkenfeld-nospam () wolke7 ! net>
Date: 2005-07-30 17:01:49
Message-ID: 3l1q3tF10l1krU1 () individual ! net
[Download RAW message or body]
phil hunt wrote:
> def normalizePath(p, *pathParts):
> """ Normalize a file path, by expanding the user name and getting
> the absolute path..
> @param p [string] = a path to a file or directory
> @param pathParts [list of string] = optional path parts
> @return [string] = the same path, normalized
> """
> p1 = os.path.abspath(os.path.expanduser(p))
> if len(pathParts)>0:
> allPathParts = [ p1 ]
> allPathParts.extend(pathParts)
> p1 = os.path.join(*allPathParts)
> p2 = os.path.abspath(p1)
> return p2
> normalisePath=normalizePath # alternate spelling
> join=normalizePath # it works like os.path.join, but better
>
>
> To be honest I don't see the point of having a Path class. That's
> the way Java does it, and I find path handling in Java to be a lot
> more of a hassle than in Python. (Actually, most things are more of
> a hassle in Java, but that's another story).
You see, with the Path class the above function could be written as
def normalizePath(p, *pathParts):
""" Normalize a file path, by expanding the user name and getting
the absolute path..
@param p [Path] = a path to a file or directory
@param pathParts [list of string/Path] = optional path parts
@return [Path] = the same path, normalized
"""
tp = p.expanduser().abspath()
return tp.joinwith(*pathParts).abspath()
That's clearly an improvement, isn't it?
Reinhold
--
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic