[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Old Man Yells At Cloud

On 2017-09-17 14:16, bartc wrote:
> print() is used for its side-effects; what relevant value does it
> return?

depending on the sink, errors can be returned (at least for the
printf(3) C function).  The biggest one I've encountered is writing
to a full disk.  The return value is how many characters were
written.  In an ideal world,

  data = "Hello" * 1000
  results = print(data)
  assert len(results) == len(data)

but if your disk is nearly full and you're redirecting data to it:

   $ python myprog.py > output.txt

it's feasible that you instruct print() to send 5000 characters but
only 4000 of them get written to the disk.  You might want to check
that condition and handle it in some more graceful way.