Skip to main content

Unix tee command for python

Project description

The Unix command tee splits the output of a program so that it is both displayed on screen and written to a file. The pyteetime package provides such a functionality in Python. It is based on the original code from A. Peck, with a few classmethods added.

Usage:

Run the example script tee-test.py listed here:

from pyteetime import tee
import sys

print('This prologue will appear on screen but not in a logfile')

LOGFILE = tee.stdout_start(append=False) # STDOUT
# from now on, all output is also copied to the logfile

tee.stderr_start(append=False) # STDERR
# from now on, all output to STDERR is also copied to stderr.log

print('This text will appear on screen and also in the logfile')

print('This will appear on screen and also in stderr.log', file=sys.stderr) 

# input from keyboard does not go to logfile:
answer = input('Enter something!\n')

# show the input to make sure it also goes into the logfile:
print('The user typed: %s' % (answer))

# data written to a file is not copied to the logfile:
DATAFILE = open('tee-test.dat','w+')
print(list(range(5)), file=DATAFILE)
DATAFILE.close()

print('This goes to the logfile but will not appear on screen', file=LOGFILE)

tee.stdout_stop()
# from now on, output to STDOUT will not go to stdout.log anymore

tee.stderr_stop()
# from now on, output to STDERR will not go to stderr.log anymore

print('This epilogue will appear on screen but not in a logfile')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyteetime-1.0.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

pyteetime-1.0.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file pyteetime-1.0.0.tar.gz.

File metadata

  • Download URL: pyteetime-1.0.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.6.9

File hashes

Hashes for pyteetime-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e639a08d4f0a87200512f73303b9bea03b9acd016b308cfd65bbdec81c0dbd22
MD5 0773dde9ce9b23504834059c77711d77
BLAKE2b-256 c3da2cbb3c2a255eda9b48382e0265ebd208e07b34f337f71cb8b3d856104842

See more details on using hashes here.

File details

Details for the file pyteetime-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyteetime-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.6.9

File hashes

Hashes for pyteetime-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 308fdc096295fff86d74a3501cc431f9fa6220136d3855ad3940ece84fc670fa
MD5 1ca244f19d686e79bae3537efe968693
BLAKE2b-256 8c58b18765217996e587a4dc17bd5e4fb823eb3b7aa9cd71db994e7d28971b5d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page