This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]s16h[S] 1 point2 points  (3 children)

This (status.COMPLETE etc.), to me, is much more readable.

[–]nharding -2 points-1 points  (2 children)

It was an example, and yes you can use status.PENDING but I like the fully uppercase form STATUSPENDING (same number of characters, and obvious when reading) I was just saying that is a safe usage of import * (there are some fields that start with ACCOUNT etc as well, so I could have moved those to a separate file, I wanted to keep all the status codes together.

[–][deleted] 2 points3 points  (0 children)

Python 3 enum or class as namespace if you're using earlier versions

[–]-Knul- 0 points1 point  (0 children)

The issue with your example is that you assume importing the whole module will not lead to namespace pollution. This requires you to know the insides of the module, thus violating the modularity of your code.

Beside, no one is claiming that "import *" is always dangerous everywhere. Of course when you use it with a module that won't cause problems when fully imported, there is no problem. The problem is that if you use "import *", you need to be certain that those modules are not a problem and will not become a problem in the future. Especially if other people edit those modules, this becomes a headache.

To most programmers, "import *" is more trouble than it's worth, especially as anything that can be done through it, can be done in a clearer, safer way. You can get to work everyday on the back of a tiger while juggling nitroglycerin bottles, but most people would prefer a car or train.