Created a "file" like command in python (see man 4 magic) and face a showstoper bug

Chris Liechti cliechti at gmx.net
Mon Jun 3 16:17:46 EDT 2002


thomas.mangin at free.fr (Thomas Mangin) wrote in 
news:359e75aa.0206031113.6a8bfed1 at posting.google.com:
> I wrote some code perform "file" like operation and I am facing a
> nasty bug.
> 
> the files can be found at : ftp://www.slhan.org/source/circle/
> 
> It produce the same output that "file":
> 
> # ./magic.py core
> core: ELF 32-bit LSB core file of 'vi' (signal 11), Intel 80386,
> version 1 (SYSV)
> 
> # ./magic.py jpg_good.jpg
> jpg_good.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI),
> 50 x 50
> 
> # ./magic.py jpg_bad.jpg
> jpg_bad.jpg: JPEG image data, EXIF standard %d.73, 10752 x 2048
> 
> Note the %d !
> 
> The code causing problem is :
> 

1. initialize replace with None

> if replace:

use this instead:
  if replace is not None:

and have fun progamming python!
chris

>   try:
>     mime = mime % replace
>   except:
>     pass
> 
> In both case mime is containing the string "%d." and replace is in
> both case of type int and valued 1 and 0.
> 
> Any idea ?
> 
> Thomas Mangin
> 



-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list