[Tutor] 'File' utility for python?
dman
dsh8290@rit.edu
Fri, 18 Jan 2002 22:56:32 -0500
On Fri, Jan 18, 2002 at 06:06:10PM -0700, VanL wrote:
| Hello,
|
| Does anyone know of a python utility that can do the same thing as the
| unix utility 'file'?
No, but I think there is a library that could probably be wrapped, or
'file' can be run in a pipe and the output looked at.
| I need to figure out if something is non-destructively editable (i.e.,
| text) before I run a search-and replace on it.
Do a search for anything that is not in the US-ASCII printable range.
That will likely suffice.
if re.search( "[^[:alnum:][:space:][:punct:]]" , <your text> ) :
print "not plain ascii"
else :
<your text> = <your text>.replace( <something> , <something else> )
-D
--
Even youths grow tired and weary,
and young men stumble and fall;
but those who hope in the Lord
will renew their strength.
They will soar on wings like eagles;
they will run and not grow weary,
they will walk and not be faint.
Isaiah 40:31