Skip to main content

captures temporarily stdout and stderr

Project description

captures temporarily stdout and stderr

Tested against Windows 10 / Python 3.10 / Anaconda

pip install stderrstdoutcapture

GetStdErr

A context manager that captures and temporarily redirects standard error (stderr) to a list.

Usage:
	from stderrstdoutcapture import GetStdErr

	def errtest():
	try:
		x = 5 / 0
	except Exception:
		return "error"

	with GetStdErr() as o2:
		returnvalue2 = errtest()
	print(o2)  # Access captured stderr as a list
	print(f"{returnvalue2=}")  # Display the return value of the function

Methods:
	__enter__(*args, **kwargs): Enter the context and redirect stderr to a StringIO buffer.
	__exit__(*args, **kwargs): Exit the context and append the captured stderr to the list.

GetStdOut

A context manager that captures and temporarily redirects standard output (stdout) to a list.

Usage:
	from stderrstdoutcapture import GetStdOut
	def outtest():
		try:
			x = 5 / 5
			print("five devided by five is one")
			return x
		except Exception:
			pass

	with GetStdOut() as o1:
		returnvalue1 = outtest()
	print(o1)  # Access captured stdout as a list
	print(f"{returnvalue1=}")  # Display the return value of the function

Methods:
	__enter__(*args, **kwargs): Enter the context and redirect stdout to a StringIO buffer.
	__exit__(*args, **kwargs): Exit the context and append the captured stdout to the list.

Project details


Release history Release notifications | RSS feed

This version

0.10

Download files

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

Source Distribution

stderrstdoutcapture-0.10.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

stderrstdoutcapture-0.10-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file stderrstdoutcapture-0.10.tar.gz.

File metadata

  • Download URL: stderrstdoutcapture-0.10.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for stderrstdoutcapture-0.10.tar.gz
Algorithm Hash digest
SHA256 36d889a09cdddb40ca5213c0318d47fd8f5b5ab4a5c7fa4361d92e01b6839f4e
MD5 90d8a87397ec5b9700d299ca829b4d7d
BLAKE2b-256 8da557b5002187fff50bdb73321f9cfd43a7a69c10adbec0e09d3c30ebccabbc

See more details on using hashes here.

File details

Details for the file stderrstdoutcapture-0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for stderrstdoutcapture-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 e37a6a8d4bc392f308866f20ee42fbdb494f63a0397aea7789829f8ace2962f3
MD5 4304379372b5d12ac492dcf3436bd4ab
BLAKE2b-256 60c35e633b8a5fb6bfcac2705b2b3c22da403c0eeccb63bf944e8dec5a2d8f35

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