lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


----- Original Message -----
From: Miles Bader
Date: 5/28/2009 10:58 PM
Joshua Jensen <jjensen@workspacewhiz.com> writes:
  
* List of os.path.* functions
The term "path" seems pretty unix-centric; perhaps simply "filename"
would be better?
  
The library was originally a Lua wrapper module called 'iox' on top of the Windows shlwapi.dll.  All of those APIs used the term "path", which could refer to a directory name or filename.  Therefore, I'm not sure referring to just a filename is sufficient.  Python has a library for pathname manipulation called os.path, too.
Also, the "slash" and "backslash" methods seem very kludgey; I don't
think users of (more or less) portable filename library should really be
thinking at that level.
  
I've always found a need to convert between the two.  Windows, for instance, accepts both forward slash and backslash filenames.
I think it's often a mistake to use terms that imply a side-effect, like
"make..." or "remove...".  It might be better to instead use terminology
that makes it clear that they return the changed filename e.g. "as_..."
or "without_...".. e.g.:

   os.filename.with_extension(filename, extension)
   os.filename.as_absolute(filename)
   os.filename.without_directory(filename)
   os.filename.without_extension(filename)
   os.filename.without_filename(filename)
  
This is certainly an interesting idea.  As I stated above, many of the names are derived from the shlwapi calls.
* os.path.append(leftPath, rightPath): Appends leftPath and rightPath
together, adding a slash between the two path components. If rightPath
is an absolute path, it is not appended to leftPath and is returned
directly.
* os.path.combine(leftPath, rightPath): Combines leftPath and rightPath,
adding a slash between the two path components and simplifying the path
by collapsing . and .. directories. If rightPath is an absolute path, it
is not appended to leftPath and is returned directly.
    
These seem slightly confusing, as they sort of refer to the physical
composition of the filename, rather than the abstract operation that's
happening (making a _truly_ portable filename library is pretty hard,
but I think it's good to try and at least operate at a slightly higher
level of abstraction than talking about slashes etc).
  
The os.path functions work on Windows, Mac OS X, and Unix platforms.  Forward slashes can be used as directory separators on all.

What common platforms did you have in mind?
Maybe something like "os.filename.in_directory(filename,directory)",
[basically, append filename to directory, unless filename is absolute,
in which case it just uses filename]?
  
I guess I find this more confusing.  I will agree that append() and combine() (or in Python's, join()) are questionable names, although both are modeled on the Win32 APIs PathAppend() and PathCombine(), for better or worse.
* os.path.escape(path): Properly escapes and quotes path, if needed.
    
There are many escape syntaxes, and which one to use depends on the
context; this method seems out of place.
  
What makes the most sense here?  If I'm building a command line, I can do:

myExecutable = '/dirA/dir with spaces/dirB/myexe'
print(os.path.escape(myExecutable))
    -- Unix: /dirA/dir\ with\ spaces/dirB/myexe
    -- Windows: "dirA/dir with spaces/dirB/myexe"

Thanks for the valued feedback.  In particular, I like the as_, with_, and without_ ideas.

Josh