[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:       zen19725 () zen ! co ! uk (phil hunt)
Date:       2005-07-31 4:47:05
Message-ID: slrndeolu9.oj7.zen19725 () cabalamat ! somewhere
[Download RAW message or body]

On Sat, 30 Jul 2005 19:01:49 +0200, Reinhold Birkenfeld <reinhold-birkenfeld-nospam@wolke7.net> wrote:
>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?

An improvement to what? To how the class is implemented, or to how 
it is used?

If you mean the former, yes is it, due to the os.path module not 
providing a function that does this. 

If you mean the latter, I disagree, because I would then have to 
call it with something like:

   pn = normalizePath(Path(p), q)

and then I would have the problem that (pn) isn't a string so 
calling a function to write some data into the file at that filename 
would no longer work, i.e. this:

   writeFile(pn, someData)

would become this:

   writeFile(pn.getString(), someData)

I don't see what having a Path type buys me. 

-- 
Email: zen19725 at zen dot co dot uk


-- 
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