On Wed, Jul 31, 2013 at 4:40 PM, Ryan <rymg19@gmail.com> wrote:
Here's something more interesting than my shlex idea.
os.path is, pretty much, the Python FS toolbox, along with shutil. But, there's one feature missing: check if a file is binary. It isn't hard, see http://code.activestate.com/recipes/173220/. But, writing 50 lines of code for a more common task isn't really Python-ish.
So...
What if os.path had a binary checker that works just like isfile: os.path.isbinary('/nothingness/is/eternal') # Returns boolean
Going right back to the beginning here. Suppose this were deemed useful. Why should it be in os.path? Nothing else there, as far as I know, looks at the *contents* of a file. Everything's looking at directory entries, sometimes not even that (eg os.path.basename is pure string manipulation). I should be able to getctime() on a file even without permission to read it. I can't see whether it's binary or text without read permission. This sounds more like a job for a file-like object, maybe a subclass of file that reads (and buffers) the first 512 bytes, guesses whether it's text or binary, and then watches everything that goes through after that and revises its guess later on. And then the question becomes: How useful would that be? But mainly, I think it's only going to cause problems to have a potentially expensive operation stuck away with the very cheap operations in os.path. ChrisA