3 ms·
> Python has to know the encoding of the "file" string by the encoding off the source file. Not when it's a string literal like in your example. The string "
by Terr_ 8y ago
> Python has to know the encoding of the "file" string by the encoding off the source file.
Not when it's a string literal like in your example.
The string "foo" has no file, not in the past, present, or reasonably-predictable future. Ditto for the literal bytes.
> It then also has to know what the encoding of the b"file" string is because it is explicitly specified.
Explicitly specified by who? Where? When?
They're just bytes, they don't have a text-encoding yet, or perhaps never: It could be a picture file, or a random seed.
- TimJYoung 8y ago<< The string "foo" has no file, not in the past, present, or reasonably-predictable future. Ditto for the literal bytes. >> Is Python not parsing/compiling the source file ? Does the "foo" string constant not live in such a source file ? << Explicitly specified by who? Where? When? >> The "b" prefix states what the encoding is: it is a raw byte string whose bytes are assumed to correspond to their ASCII counterparts.