pdf to text

Steve Holden steve at holdenweb.com
Tue Jan 30 00:22:45 EST 2007


tubby wrote:
> Dieter Deyke wrote:
>>>     sout = os.popen('pdftotext "%s" - ' %f)
> 
>> Your program above should read:
>>
>>    sout = os.popen('pdftotext "%s" - ' % (f,))
> 
> What is the significance of doing it this way?

It's actually just nit-picking - as long as you know f is never going to 
  be a tuple then it's perfectly acceptable to use a single value as the 
right-hand operand.

Of course, if f ever *is* a tuple (with more than one element) then you 
will get an error:

  >>> for f in ['string',
                ('one-element tuple', ),
                ("two-element", "tuple")]:
  ...   print 'Nit: pdftotext "%s" - ' % (f,)
  ...   print 'You: pdftotext "%s" - ' %f
  ...
Nit: pdftotext "string" -
You: pdftotext "string" -
Nit: pdftotext "('one-element tuple',)" -
You: pdftotext "one-element tuple" -
Nit: pdftotext "('two-element', 'tuple')" -
Traceback (most recent call last):
   File "<stdin>", line 3, in <module>
TypeError: not all arguments converted during string formatting
  >>>

So there is potentially some value to it. But we often don't bother.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb     http://del.icio.us/steve.holden
Blog of Note:          http://holdenweb.blogspot.com
See you at PyCon?         http://us.pycon.org/TX2007




More information about the Python-list mailing list