Fix Python – How to write string literals in python without having to escape them?

Is there a way to declare a string variable in python such that everything inside of it is automatically escaped, or has its literal character value?
I’m not asking how to escape the quotes with slashes, that’s obvious. What I’m asking for is a general purpose way for making everything in a string literal so that I don’t have to manually go throu….

Fix Python – How to escape os.system() calls?

When using os.system() it’s often necessary to escape filenames and other arguments passed as parameters to commands. How can I do this? Preferably something that would work on multiple operating systems/shells but in particular for bash.
I’m currently doing the following, but am sure there must be a library function for this, or at least a more….

Fix Python – Process escape sequences in a string in Python

Sometimes when I get input from a file or the user, I get a string with escape sequences in it. I would like to process the escape sequences in the same way that Python processes escape sequences in string literals.
For example, let’s say myString is defined as:
>>> myString = “spam\\neggs”
>>> print(myString)

I want a function (I’ll c….

Fix Python – How can I selectively escape percent (%) in Python strings?

I have the following code
test = “have it break.”
selectiveEscape = “Print percent % in sentence and not %s” % test


I would like to get the output:
Print percent % in sentence and not have it break.

What actually happens:
selectiveEscape = “Use percent % in sentence and not %s” % test
TypeError: %d format: a number is….

Fix Python – Saving utf-8 texts with json.dumps as UTF8, not as \u escape sequence

Sample code:
>>> import json
>>> json_string = json.dumps(“ברי צקלה”)
>>> print(json_string)
“\u05d1\u05e8\u05d9 \u05e6\u05e7\u05dc\u05d4”

The problem: it’s not human readable. My (smart) users want to verify or even edit text files with JSON dumps (and I’d rather not use XML).
Is there a way to serialize objects into UTF-8 JSON strings (instead ….