Search notes:

Python: printf using ctypes

The ctypes standard library allows use the standard C lib's implementation of printf.
Note that the use of b'…' literals is required when calling printf.

Linux

import ctypes

libc = ctypes.cdll.LoadLibrary("libc.so.6")

chars_printed = libc.printf(b'num: %d, txt: %s\n', 42, b'Hello World')

Windows

import ctypes

libc = ctypes.cdll.msvcrt

chars_printed = libc.printf(b'num: %d, txt: %s\n', 42, b'Hello World')

See also

string.format()

Links

This Stackoverflow answer was very helpful and served as basis for the information on this page.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1740476424, '3.137.159.47', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/standard-library/ctypes/printf(60): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78