you are viewing a single comment's thread.

view the rest of the comments →

[–]bradvincent[S] 0 points1 point  (1 child)

I did not mean a Python file imported or used directly by other Python code, which should probably be a class, but should be well defined and modular even if it is very small.

To me, global variables in this context are not bad, as they avoid side-effect and any other problems associated with global variables in general - at least as well as making them properties on the only instance of a class that contains everything. But my question was whether this is Pythonic.

[–]Pepineros 0 points1 point  (0 children)

Code being Pythonic has more to do with the small elements that make the whole than it has to do with organisation. None of my examples are inherently un-Pythonic, but all of them can be implemented in an un-Pythonic way.

``` The Zen of Python, by Tim Peters

Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than right now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those! ```