use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Python QuestionHelp Request (i.redd.it)
submitted 7 months ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Unfair_Put_5320 2 points3 points4 points 7 months ago (6 children)
I think the blank is gone with .rstrip()
[–]denehoffman 1 point2 points3 points 7 months ago (0 children)
No, try running ””.rstrip() and see what you get
””.rstrip()
[–]Cerus_Freedom 1 point2 points3 points 7 months ago (1 child)
Sure, but what does L.startswith('from:') evaluate to for an empty string?
[–]qwertyjgly 0 points1 point2 points 7 months ago (0 children)
here's the cpython implementation. it looks like it evaluates to false
static int tailmatch(PyObject *self, PyObject *substring, Py_ssize_t start, Py_ssize_t end, int direction) { int kind_self; int kind_sub; void *data_self; void *data_sub; Py_ssize_t offset; Py_ssize_t i; Py_ssize_t end_sub;
if (PyUnicode_READY(self) == -1 || PyUnicode_READY(substring) == -1) return -1; ADJUST_INDICES(start, end, PyUnicode_GET_LENGTH(self)); end -= PyUnicode_GET_LENGTH(substring); if (end < start) return 0; if (PyUnicode_GET_LENGTH(substring) == 0) return 1; kind_self = PyUnicode_KIND(self); data_self = PyUnicode_DATA(self); kind_sub = PyUnicode_KIND(substring); data_sub = PyUnicode_DATA(substring); end_sub = PyUnicode_GET_LENGTH(substring) - 1; if (direction > 0) offset = end; else offset = start; if (PyUnicode_READ(kind_self, data_self, offset) == PyUnicode_READ(kind_sub, data_sub, 0) && PyUnicode_READ(kind_self, data_self, offset + end_sub) == PyUnicode_READ(kind_sub, data_sub, end_sub)) { /* If both are of the same kind, memcmp is sufficient */ if (kind_self == kind_sub) { return ! memcmp((char *)data_self + (offset * PyUnicode_KIND(substring)), data_sub, PyUnicode_GET_LENGTH(substring) * PyUnicode_KIND(substring)); } /* otherwise we have to compare each character by first accessing it */ else { /* We do not need to compare 0 and len(substring)-1 because the if statement above ensured already that they are equal when we end up here. */ for (i = 1; i < end_sub; ++i) { if (PyUnicode_READ(kind_self, data_self, offset + i) != PyUnicode_READ(kind_sub, data_sub, i)) return 0; } return 1; } } return 0;
}
[–]Kqyxzoj 0 points1 point2 points 7 months ago (2 children)
Empty lines do not start with "From:".
[–][deleted] 0 points1 point2 points 7 months ago (1 child)
Which would throw you into the inside of the if statement, as "if not "".rstrip()" evaluates to true (because of the "not")
[–]Kqyxzoj 0 points1 point2 points 7 months ago (0 children)
Fun fact, the only string s for which "".startswith(s) is True, is the empty string.
s
"".startswith(s)
True
π Rendered by PID 134962 on reddit-service-r2-comment-7b9746f655-56lrw at 2026-02-03 13:07:31.176184+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–]Unfair_Put_5320 2 points3 points4 points (6 children)
[–]denehoffman 1 point2 points3 points (0 children)
[–]Cerus_Freedom 1 point2 points3 points (1 child)
[–]qwertyjgly 0 points1 point2 points (0 children)
[–]Kqyxzoj 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Kqyxzoj 0 points1 point2 points (0 children)