Function to call a extern command as a filter

Rhodri James rhodri at kynesim.co.uk
Wed Sep 25 14:03:36 EDT 2019


On 25/09/2019 18:00, lain.mailinglist via Python-list wrote:
> 
>> On 25/09/2019 12:04, Ulrich Goebel wrote:
>>
>>> Hello,
>>> what I want:
>>> I want a function which converts a markdown-formatted string to a
>>> latex-formatted string
>>
>> [snip]
>>
>>> I have a extern tool pandoc which does exactly what I want, but it
>>> works on files. This tool is able to work as a pipe, so it uses
>>> the standard input and standard outpu.
>>> What I could do:
>>> def markdown_to_latex (m : string)
>>>      write the string m to a file
>>>      call pandoc to work on that file
>>>      read the outputfile into the string l
>>>      return (l)
>>> What would be nice:
>>> I would like to avoid the extra steps writing an reading extern files.
>>
>> subprocess is your friend here. Something like:
[snip myself]

> 
> You can also use the io.StringIO class of the stdlib, which is more suitable for this use case.

Not for running external tools, surely?

-- 
Rhodri James *-* Kynesim Ltd



More information about the Python-list mailing list