Skip to content

Instantly share code, notes, and snippets.

@ddrscott
Created November 12, 2017 11:25
Show Gist options
  • Select an option

  • Save ddrscott/9a78e90ebf14c2c8b399dc51a3939a7d to your computer and use it in GitHub Desktop.

Select an option

Save ddrscott/9a78e90ebf14c2c8b399dc51a3939a7d to your computer and use it in GitHub Desktop.
Example checking for std in data.
import logging
import sys
from tempfile import SpooledTemporaryFile
try:
with SpooledTemporaryFile() as temp:
temp.write(sys.stdin.read())
logging.debug("tell: %i" % temp.tell())
if temp.tell() > 0:
temp.seek(0)
# do something with the data
except Exception as msg:
logging.error("could not read stdin:")
logging.error(msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment