Skip to content

Instantly share code, notes, and snippets.

Redirecting embedded Python’s I/O
Posted on 2012-4-13 by mvasilkov
When using Python for application scripting, more often than not you want to redirect interpreter’s input/output to the embedding program. This is how it’s done with the Python/C API:
PyObject *sys = PyImport_ImportModule("sys");
PyObject *out = PyFile_FromString("python_out", "w+");
PyObject_SetAttrString(sys, "stdout", out);
Pretty intuitive, right? Now embedded Python’s stdout points to the newly created file, python_out. Working with the script’s output from C is also trivial:
@FigBug
FigBug / https_to_ssh
Created January 12, 2018 17:00
Convert git repo from https to ssh
#/bin/bash
#-- Script to automate https://help.github.com/articles/why-is-git-always-asking-for-my-password
REPO_URL=`git remote -v | grep -m1 '^origin' | sed -Ene's#.*(https://[^[:space:]]*).*#\1#p'`
if [ -z "$REPO_URL" ]; then
echo "-- ERROR: Could not identify Repo url."
echo " It is possible this repo is already using SSH instead of HTTPS."
exit
fi
@FigBug
FigBug / Script Markers.js
Created September 26, 2022 03:06
Script Markers
function ScriptMarkers() {
// Variables: these must be filled out so the session knows your controller layout
this.deviceDescription = "Script Markers"; // device name
this.needsMidiChannel = false; // send midi controller to daw
this.needsMidiBackChannel = false; // send midi daw to controller
this.needsOSCSocket = false; // communicate via osc
this.numberOfFaderChannels = 0; // number physical faders
this.numCharactersForTrackNames = 0; // characters of channel text
this.numCharactersForAuxLabels = 0; // characters of aux text
Alright , the following podcast will not be possible without my amazing executive producers , Jonathan Kaplan , Russ Matkin , Ben Sherman , Ian A . Chapman , Barry A . Spath , Lori Elsroth , Michael Elsroth , J .C . Dingus , and America's favorite public defender , David Donnelly . Thank you guys so much for making this podcast possible . Enjoy it . Hey , I'm Matt , and this is a very special , "Abracababble." Alright , so normally this is a private podcast , a member's only podcast , but this podcast needs to go out to the masses , right? This is a very shareable piece of information . I have two very special guests with me today . I have a embattled magician , Garrett Thomas . Liar . And I have the judge of Foulas back on for the second time , Mike Close . Here come the judge . Here come the judge . Nice to be here , Matt . Thanks for having me . No problem . No problem . I'm glad to talk about this , and we're going to have some fun . So good to see you again . So no , it's good to see you , Garrett . And