CodeSOD: Install Your Package

This post was originally published on this site

The Daily WTF

I use Python a lot at work, and if you’re doing anything vaguely data oriented, you want to use NumPy. I gave a talk about how much I love NumPy. It’s one of the things that I automatically include in every requriements.txt because it’s so goddamn useful.

Lanny supports a product which uses NumPy, which is why he was surprised to find this block:

#################### Import Section of the code ############################# try: import numpy as np except Exception as e: print(e,”nPlease Install the package”) #################### Import Section ends here ################################

Now, Python is perfectly happy to let you put code inline in modules. This allows for useful idioms- like, for example, I often do import blocks like this in the entry point script of a product:

if mode == “debugging”: from debugging_main import main elif mode == “server”: from server_main import main elif mode == “client”: from client_main

To read the full article click on the 'post' link at the top.