Import Error: No module named numpy Anaconda

If you are using Anaconda3 then you should already have numpy installed. There is no reason to use pip. My guess is that the Anaconda distribution is possibly not on your path and you are picking up some other system python. You should run where python (or where python3) to see which one you are using. If the executable … Read more

Difference between except: and except Exception as e:

In the second you can access the attributes of the exception object: But it doesn’t catch BaseException or the system-exiting exceptions SystemExit, KeyboardInterrupt and GeneratorExit: Which a bare except does: See the Built-in Exceptions section of the docs and the Errors and Exceptions section of the tutorial for more info.

log2 in python math module

why doesn’t it exist? >>> [‘log’, ‘log10’, ‘log1p’] I know I can do log(x,2), but log2 is really common, so I’m kind of baffled. Oh, it looks like it’s only defined in C99, not C90, I guess that answers my question. Still seems kind of silly.

Insert some string into given string at given index in Python

An important point that often bites new Python programmers but the other posters haven’t made explicit is that strings in Python are immutable — you can’t ever modify them in place. You need to retrain yourself when working with strings in Python so that instead of thinking, “How can I modify this string?” instead you’re thinking “how … Read more

Converting from a string to boolean in Python?

Really, you just compare the string to whatever you expect to accept as representing true, so you can do this: Or to checks against a whole bunch of values: Be cautious when using the following: Empty strings evaluate to False, but everything else evaluates to True. So this should not be used for any kind of parsing … Read more