Trying to figure out where to define package-wide constants.#4
Trying to figure out where to define package-wide constants.#4agartland wants to merge 1 commit intouwescience:masterfrom
Conversation
|
@agartland . Interesting. There are three things one may think of when trying to do this, and I think you are asking how the 3rd is done (which I don't know how to do). I can set up the first 2:
as in (2), but externally Forgot to say, I also put examples of how I usually would do it, but requires an import statement in the file you are importing to https://github.com/rbiswas4/shablona/tree/package_wide_constants_normal and using builtins (and not requiring imports, but clogging up the external namespace) in https://github.com/rbiswas4/shablona/tree/package_wide_constants/shablona |
|
Strange. This does seem to work for me (assuming I am understanding what you are trying to do here). See #5 for a test that passes on my machine (and hopefully also on Travis). If that misses the mark, maybe you could add a test that fails, to demonstrate what it is that you are trying to do? |
|
I eat my words! That works on my machine, but fails on Travis. Let me see if I can make sense of this... |
|
OK - looks like the solution might be to do this: Is there some use-case that isn't covered by that? |
@arokem
Currently this isn't working and I'm hoping you either know the right way to do this or can help me figure it out. The scenario is that I have a set of constants that should be defined package-wide and they should be importable by any module (or any module within a subpackage, which doesn't really apply here yet).
It sounds like one can either define them in
__init__.pyor a new module e.g.constants.pyif you don't want to clutter your init. But I can't get either to work. Please let me know if you have ideas to try!Thanks