In C++, the std::quoted
stream manipulator produces a quoted and escaped version of a string:
std::string dirPath = "C:\Documents\Oval Office Recordings\Launch Codes.txt";
std::cout << dirPath << endl; // C:DocumentsOval Office RecordingsLaunch Codes.txt
std::cout << std::quoted(dirPath) << endl; // "C:\Documents\Oval Office Recordings\Launch Codes.txt"
Is there a direct Python f-string equivalent to std::quoted
? By “direct,” I mean “built into Python” rather than “you can roll your own version.”