I just ran into what seemed to me to be bizarre string formatting behavior in python. It turned out to be caused by carriage return characters ('\r') I didn't know were there. Here's an example:
>>> text = 'hello\r' >>> '(SUBJECT "%s")' % (text) '(SUBJECT "hello\r")' >>> print '(SUBJECT "%s")' % (text) ")UBJECT "hello I tried the same thing in C (on a couple machines) as a sanity check.
#include <stdio.h> int main() { char *text = "hello\r"; printf("(SUBJECT \"%s\")\n", text); return 0; } Output:
% ./a.out ")UBJECT "hello Is this desired behavior? If so, can someone explain what is going on?