How should I write a Windows path in a Python string literal?

you can use always: ‘C:/mydir’ this works both in linux and windows. Other posibility is ‘C:\\mydir’ if you have problems with some names you can also try raw string literals: r’C:\mydir’ however best practice is to use the os.path module functions that always select the correct configuration for your OS: os.path.join(mydir, myfile) From python 3.4 … Read more

What’s the “E” before a Postgres string?

As per the PostgreSQL documentation https://www.postgresql.org/docs/9.0/sql-syntax-lexical.html (emphasis mine) PostgreSQL also accepts “escape” string constants, which are an extension to the SQL standard. An escape string constant is specified by writing the letter E (upper or lower case) just before the opening single quote, e.g., E’foo’. (When continuing an escape string constant across lines, write E … Read more

Should I compare a std::string to “string” or “string”s?

Neither. If you want to be clever, compare to “string”sv, which returns a std::string_view. While comparing against a literal like “string” does not result in any allocation-overhead, it’s treated as a null terminated string, with all the concomittant disadvantages: No tolerance for embedded nulls, and users must heed the null terminator. “string”s does an allocation, … Read more

Include )” in raw string literal without terminating said literal

Raw string literals let you specify an almost arbitrary* delimiter: //choose ### as the delimiter so only )###” ends the string R”###( Some Text)” )###”; *The exact rules are: “any member of the basic source character set except: space, the left parenthesis (, the right parenthesis ), the backslash \, and the control characters representing … Read more

Why do string literals (char*) in C++ have to be constants?

Expanding on Christian Gibbons’ answer a bit… In C, string literals, like “Hello, World!”, are stored in arrays of char such that they are visible over the lifetime of the program. String literals are supposed to be immutable, and some implementations will store them in a read-only memory segment (such that attempting to modify the … Read more

C/C++, can you #include a file into a string literal? [duplicate]

The C/C++ preprocessor acts in units of tokens, and a string literal is a single token. As such, you can’t intervene in the middle of a string literal like that. You could preprocess script.py into something like: “some code\n” “some more code that will be appended\n” and #include that, however. Or you can use xxd​ … Read more

Why are my two tuples containing strings, created the same way, not equal?

You are comparing pointers to buffers of characters, not strings. Sometimes the compiler will turn two different “one”s into the same buffer, sometimes it will not. In your case, it isn’t. Probably a debug build. Add #include <string_view>, then using namespace std::literals; auto t1 = std::make_tuple(“one”sv, “two”sv, “three”sv); auto t2 = std::make_tuple(“one”sv, “two”sv, “three”sv); and … Read more