Detecting Binary content in files
Hi, I'm wondering if Python has a utility to detect binary content in files? Or if anyone has any ideas on how that can be accomplished? I haven't been able to find any useful information to accomplish this (my other option is to fire off a perl script from within m python script that will tell me whether the file is binary), so any pointers will be appreciated. Thanks, Ritu -- http://mail.python.org/mailman/listinfo/python-list
Re: Detecting Binary content in files
On Mar 31, 10:19 am, Josh Dukes wrote:
> There might be another way but off the top of my head:
>
> #!/usr/bin/env python
>
> def isbin(filename):
> fd=open(filename,'rb')
> for b in fd.read():
> if ord(b) > 127:
> fd.close()
> return True
> fd.close()
> return False
>
> for f in ['/bin/bash', '/etc/passwd']:
> print "%s is binary: " % f, isbin(f)
>
> Of course this would detect unicode files as being binary and maybe
> that's not what you want. How are you thinking about doing it in
> perl exactly?
With perl, I'm thinking of doing something like the below:
if ( ( -B $filename ||
$filename =~ /\.pdf$/ ) &&
-s $filename > 0 ) {
return(1);
}
So my isbin method should return a true for any file that isn't
entirely ASCII text, so I guess for my purposes classifying a unicode
file as a 'binary' would be alright. Thanks much for your response.
>
> On Tue, 31 Mar 2009 09:23:05 -0700 (PDT)
>
> ritu wrote:
> > Hi,
>
> > I'm wondering if Python has a utility to detect binary content in
> > files? Or if anyone has any ideas on how that can be accomplished? I
> > haven't been able to find any useful information to accomplish this
> > (my other option is to fire off a perl script from within m python
> > script that will tell me whether the file is binary), so any pointers
> > will be appreciated.
>
> > Thanks,
> > Ritu
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> --
>
> Josh Dukes
> MicroVu IT Department
--
http://mail.python.org/mailman/listinfo/python-list
Query
Hi , I am using linked server to fetch data from Oracle database. Now ,I have to use FPN_STATUS='A' in the query. Kindly tell me if there is an escape sequence for ' . FROM OPENQUERY(FPDWH, 'SELECT WGFP_OWN.GRS_FILE_PLAN_VERSION.FVN_STATUS FPN_STAT_CODE, WGFP_OWN.GRS_FILE_PLAN_STATUS.FPS_NAME FPN_STAT_NAME, WGFP_OWN.GRS_FILE_PLAN_VERSION.FVN_STAT_UPD_BY FPN_STAT_UPD_BY, FROM WGFP_OWN.GRS_FILE_PLAN_VERSION, WGFP_OWN.GRS_FILE_PLAN, WGFP_OWN.GRS_FILE_PLAN_STATUS, WGFP_OWN.GRS_SECTOR, (SELECT A.FVN_FPN_ID AS FPN_NO, A.FVN_ID AS FVN_ID FROM WGFP_OWN.GRS_FILE_PLAN_VERSION A, WGFP_OWN.GRS_FILE_PLAN B WHERE B.FPN_ID = A.FVN_FPN_ID AND A.FVN_VERSION=1 AND (A.FVN_FPN_ID) NOT IN (SELECT C.FVN_FPN_ID AS FPN_NO_A FROM WGFP_OWN.GRS_FILE_PLAN_VERSION C, WGFP_OWN.GRS_FILE_PLAN D WHERE D.FPN_ID = C.FVN_FPN_ID AND C.FVN_STATUS ='A') UNION SELECT A.FVN_FPN_ID AS FPN_NO, A.FVN_ID AS FVN_ID FROM WGFP_OWN.GRS_FILE_PLAN_VERSION A, WGFP_OWN.GRS_FILE_PLAN B WHERE B.FPN_ID = A.FVN_FPN_ID AND *A.FVN_STATUS ='A' --- Any alternative for ' character *--GROUP BY A.FVN_FPN_ID ) FVN_MAX Now ,I have to use FPN_STATUS='A' in the query. Kindly tell me if there is an escape sequence for ' . Hoping for an early reply. *Thanks * *Ritu *** -- http://mail.python.org/mailman/listinfo/python-list
