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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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