What does an ‘r’ represent before a string in python?

r means the string will be treated as raw string. See the official Python 2 Reference about “String literals”: When an ‘r’ or ‘R’ prefix is present, a character following a backslash is included in the string without change, and all backslashes are left in the string. For example, the string literal r”\n” consists of two characters: a backslash and a lowercase ‘n’. String quotes can be … Read more

Homebrew brew doctor warning about /Library/Frameworks/Python.framework, even with brew’s Python installed

I had the same problem. When I upgraded python3 through Homebrew, I started getting this: I had the same conflict with Python somehow being installed in /Library/Framework/Python.framework. I just did a brew link overwrite and everything is working fine now. There is some info about what to do with the Python version in the /Library/Framework/Python.framework here. I guess you could … Read more

input() error – NameError: name ‘…’ is not defined

TL;DR input function in Python 2.7, evaluates whatever your enter, as a Python expression. If you simply want to read strings, then use raw_input function in Python 2.7, which will not evaluate the read strings. If you are using Python 3.x, raw_input has been renamed to input. Quoting the Python 3.0 release notes, raw_input() was renamed to input(). That is, the new input() function reads a … Read more

In python, how can I print lines that do NOT contain a certain string, rather than print lines which DO contain a certain string:

The problem isn’t your use of not, it’s that or doesn’t mean what you think it does (and if you think it through, it couldn’t): You’re asking whether the expression (“StatusRequest” or “StatusResponse”) appears in line. But that expression is just the same thing as “StatusRequest”. Put it in English: you’re not trying to say “if neither of these is in line”. Python … Read more