Even if you are in an automated context, not using a typical browser, fetching the data/webpage from an URL is easy. There are command line tools like wget and curl, and every programming library has its share of libraries to build on.

But what if you need the HTML markup of page after it has been manipulated with JavaScript?

A colleague of mine at work has set up his IDE to clean up all trailing whitespace on save. Nothing wrong with that, except that he is the only one, which very often means in practice that his commits are sprinkled with fixes of other people's whitespace mixups. Because of these unrelated line changes, you easily get in conflict situations when cherry-picking or merging.

Here is a trick I use to cherry-pick this kind of commits, without the whitespace parts.

So you have some Python code in a try-catch, and you want the typical Python stacktrace (aka traceback, aka backtrace) in a way you can manipulate?
Here are some clues:

importtracebackimportloggingtry:
stuff()exceptException:
# Just print tracebackprint"something went wrong, here is some info:"traceback.print_exc()# Get traceback as a string and do something with it
error = traceback.format_exc()print error.upper()# Log it through logging channellogging.error('Something went wrong', exc_info=True)

Music files come, music files go. And after some time your iTunes library is sprinkled with cases of The song “Jajazazalala” could not be used because the original file could not be found. Would you like to locate it?

After you fix the conflicts manually in the files, you normally want to tell git that the conflict has been resolved. If you google for how to do this, you typically find solutions that suggest to git add the files and commit. But what if your (stashed) work is not ready for commit/staging yet?

As its name suggests, the Python subprocess allows you to spawn a child/sub process and keep an eye on its standard output through a pipe for example. Very handy to glue together external systems/processes. A tricky issue with having parallel "flows" this way (your python process and the child process in this case), is the risk on deadlocks if you are not careful with the order things are done.