Can Syntax Errors be handled?

SyntaxError is a perfectly ordinary built-in exception. It is not special in any way. Only the circumstances of when it’s (usually) thrown are a bit unusual. A syntax error means that the code featuring said error cannot be parsed. It doesn’t even begin to be a valid program, hence it cannot be executed. Therefore SyntaxError … Read more

Can Syntax Errors be handled?

SyntaxError is a perfectly ordinary built-in exception. It is not special in any way. Only the circumstances of when it’s (usually) thrown are a bit unusual. A syntax error means that the code featuring said error cannot be parsed. It doesn’t even begin to be a valid program, hence it cannot be executed. Therefore SyntaxError … Read more

python multiprocessing in Jupyter on Windows: AttributeError: Can’t get attribute “abc”

I got multiprocessing to work from within a Jupyter notebook on Windows by saving my function in a separate .py file and including that file in my notebook. Example: f.py: def f(name, output): output.put(‘hello {0}’.format(name)) return Code in Jupyter notebook: from multiprocessing import Process, Queue #Having the function definition here results in #AttributeError: Can’t get … Read more

What’s the most efficient way to convert a MySQL result set to a NumPy array?

This solution uses Kieth’s fromiter technique, but handles the two dimensional table structure of SQL results more intuitively. Also, it improves on Doug’s method by avoiding all the reshaping and flattening in python data types. Using a structured array we can read pretty much directly from the MySQL result into numpy, cutting out python data … Read more

Defining multiple plots to be animated with a for loop in matplotlib

In the solution below I showcase a bigger example (with also bar plot) that may help people understand better what should be done for other cases. After the code I explain some details and answer the bonus question. import matplotlib matplotlib.use(‘Qt5Agg’) #use Qt5 as backend, comment this line for default backend from matplotlib import pyplot … Read more