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.
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.
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.