Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Redirects text send to sys.stdout/stderr from Python to a user defined C/C++ function.

License

NotificationsYou must be signed in to change notification settings

TinyTinni/PyLogHook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CMake
Redirects text send to sys.stdout/stderr from Python to a user defined C/C++ function.

When you write your own interpreter for embedded python, you are maybe interested inthe output given by the Python interpreter.This header-only project provvides the functionality to passthe output to any given function.

Features

  • redirect stdout/stderr to a plain function, lambda or Functor
  • supports GUI programs without default console
  • doesn't add any function to pythons global namespace
  • doesn't add any additional python module

Requirements

If you use Boost, define TYTI_PYLOGHOOK_USE_BOOST before include PyLogHook.h.

Install

It is header only. Just addPyLogHook.h to your project which should already link against boost.python or pybind11.

How-To

Call one of the functions in namespacetyti::pylog.

// in case of using Boost.Python#defineTYTI_PYLOGHOOK_USE_BOOST//------------------------------#include<PyLogHook.h>voidmy_stdout(constchar* w){    std::cout << w;}voidmy_stderr(constchar* w){    std::cerr << w;}...//somewhere e.g. in your main function, after Py_Initialize()tyti::pylog::redirect_stdout(my_stdout);tyti::pylog::redirect_stderr(my_stderr);

Preconditions

Before calling one of the functions, make sure

  • python is initalized (Py_Initialize())
  • you hold the GIL, if multithreading is activated

Exceptions

If anything went wrong, a Python exception was raised.You can check, if a there is a pending exception viaPyErr_Occurred() (Seetests).

License

MIT License © Matthias Möller. Made with ♥ in Germany.

About

Redirects text send to sys.stdout/stderr from Python to a user defined C/C++ function.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp