plumbum: How to send a variable to stdin?

236 Views Asked by At

I currently do:

(local['echo'][var] | sth)()

Which seems inelegant and inefficient.

1

There are 1 best solutions below

0
On BEST ANSWER

I found the solution in the plumbum documentation:

You can use the shift-left operator <<.

from plumbum import local

if __name__ == '__main__':
    var = "some text in a python variable"

    sth = local["cat"]

    x = (local['echo'][var] | sth)()
    print(x)

    print("alternative:")
    x = (sth << var)()
    print(x)