[Spambayes] Unwanted stock solicitations
Luigi Pugnetti
pl at symbolic.it
Fri Nov 3 11:35:21 CET 2006
On Fri, 2006-11-03 at 11:26 +0100, Vibe Grevsen wrote:
> Hi Luigi,
>
>
> > > os.popen3() does not seem to support the read()-method?
>
> > Are you sure?
>
> ------------
>
> Yep, seems so at least in Python 2.5:
>
> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import os
> >>> ocr_cmd = ur'ocrad -s %s -c %s "%s"' % ("2", "ascii", "c:\logo.pgm")
>
> >>> os.popen3( ocr_cmd ).read()
> __main__:1: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> AttributeError: 'tuple' object has no attribute 'read'
>
> >>> os.popen( ocr_cmd ).read()
> '- Unlo_k Arhus -\n\n'
ok. this is the problem. popen returns 3 files descriptor
you have to use something like:
fin, fout, ferr = os.popen3(cmd)
fout.read()
> >>>
>
>
> > commented calling ocrad using popen3 and it works (at least on of a few
> > computers I tested it)
>
> Hmm, strange. For the record, which OS are you using it on?
>
>
>
> > > > On windows you have to put quote around pnmfile to protect against space
> > > > in path (also un linux you should have them but it's unlikely you get a
> > > > path with a space).
> >
> > > Oh, YES, you're absolutely right.
> > > Thank you for this suggestion.
> >
> >
> > > > On windows there is also an other caveat.
> > > > you should put quote also around ocrad path but if you do that you have
> > > > to quote everything.
> > > > to explain the command should be:
> >
> > > > ocr_cmd = r'""ocrad_path" -s %s -c %s "%s""'%(scale, charset, pnmfile)
> > > > fin, fout, ferrr = os.popen3(ocr_cmd)
> >
> > > I tested your suggestion, but it seemed to resolve wrong in the interpreter.
> > > Also popen3() could not be read() so I changed it a bit
>
> > Strange. It's work for me
>
> The tripple-quoting resolved wrong I think. I don't understand it completely.
> Maybe because it's already a raw string?
>
>
>
> > > # u: unicode support, r: raw string
> > > ocr_cmd = ur'ocrad -s %s -c %s "%s"' % (scale, charset, pnmfile)
> > > ocr = os.popen( ocr_cmd )
> > >
> > > I also tested this
> > >
> > > # u: unicode support, r: raw string
> > > ocr_cmd = ( ur'ocrad -s %s -c %s < "%s" 2>' + os.path.devnull ) % (scale, charset, pnmfile)
> > > ocr = os.popen( ocr_cmd )
> > >
> > > Both working in windows so Skip can pick whichever he likes best ;)
>
> > Does 2> really work? I think it kind of works because it's ignored by
> > cmd.exe but it's a unix sh construct (I'm not really sure if it even
> > works using csh derived shells)
>
> Yes, it works in NT, XP and 2k: http://shorterlink.com/?P3W1A9
> (You may even learn some tricks from that article)
interesting. thank you for the info.
>
>
>
> > > > using -s (and other flags as well) disable -x.
> > >
> > > Hmm, bug, no, better undocumented feature? :)
>
> > oh yes, you have to look inside the source code to find it
>
> Okay ...
>
>
>
> > > > orf file is never used. probably is there from the start before skip
> > > > introduce the scale parameter
> > >
> > > Actually he tries to count the number of lines in orf I think
>
> > no, he looks for line starting with line that probably it's related to
> > the number of line in the output.
>
> Not sure - I'd never even opened a .py file ten days ago :) - but this
>
> ctokens.add("image-text-lines:%d" %
> int(log2(nlines)))
>
> makes me suspicious... Skip?
>
>
>
> Happy coding :)
>
> Vibe
> _______________________________________________
> SpamBayes at python.org
> http://mail.python.org/mailman/listinfo/spambayes
> Check the FAQ before asking: http://spambayes.sf.net/faq.html
--
Luigi Pugnetti
Symbolic S.p.A.
V.le Mentana, 29
I-43100 Parma
Italy
Tel: +39 0521 708811
Fax: +39 0521 776190
More information about the SpamBayes
mailing list