0

I'm trying to print my text file with 'lpr' in linux Ubuntu

import os
import tempfile

s = 'mystring'
f = tempfile.mktemp('.txt')
open(f,'w').write(s)

os.system("lpr -P myprinter_name f")

but I get this error:

lpr: Error - unable to access "f" - No such file or directory

How can I create tempfile without getting this error

THANKS!!!

nix20536
  • 35
  • 5
  • You need to insert the contents of the variable named `f`, not just put an `f` in your string literal. Is this python? – Ben Voigt Sep 12 '22 at 18:59
  • 2
    Q: What language? Note: "f" is a VARIABLE. You need to pass the VALUE of the variable to the "lpr" command (e.g. "myfile.txt"), not the variable name ("f")... EXAMPLE: `cmd = "lpr -P myprinter_name " + f`, then `os.system(cmd)` – paulsm4 Sep 12 '22 at 18:59
  • Thank you paulsm4 for your help, your code works fine! – nix20536 Sep 12 '22 at 19:15

0 Answers0