Python: list of lists

Lists are a mutable type – in order to create a copy (rather than just passing the same list around), you need to do so explicitly: However, list is already the name of a Python built-in – it’d be better not to use that name for your variable. Here’s a version that doesn’t use list as a variable name, … Read more

How to write inline if statement for print?

Python does not have a trailing if statement. There are two kinds of if in Python: if statement: if condition: statement if condition: block if expression (introduced in Python 2.5) expression_if_true if condition else expression_if_false And note, that both print a and b = a are statements. Only the a part is an expression. So … Read more

How to remove EOFError: EOF when reading a line?

Nothing is overlooked. As per the documentation input raises an EOFError when it hits an end-of-file condition. Essentially, input lets you know we are done here there is nothing more to read. You should await for this exception and when you get it just return from your function or terminate the program.

Where does pip install its packages?

pip when used with virtualenv will generally install packages in the path <virtualenv_name>/lib/<python_ver>/site-packages. For example, I created a test virtualenv named venv_test with Python 2.7, and the django folder is in venv_test/lib/python2.7/site-packages/django.