I try to stick to the PEP8 coding conventions. I have a package called main. Inside the package there is a module called time, which has a class called Time inside. Now I have a bit of trouble finding a suitable name for my actual instance because time, which would be usually my choice, is already taken by the module and there seems to be a name-clash if I name it this way.
from main.time import Time
time = Time()
...
if time.status == main.time.STOPPED
Maybe I also placed the constant in the wrong module, but I thought that it would be better to have my constants at the place where they belong to. This is a constant used in my class Time (and the main module), so I can make sure that I don't mix it up with another constant called STOPPED used for player movement. Unfortunately I get an AttributeError: 'function' object has no attribute 'time'.
What would be the best solution here? Rename the constants to TIME_STOPPED and PLAYER_STOPPED and put them into a constants module? Naming my instance variable my_time or time_ or something like this is not really what I would like to do. What's the Pythonic way?
STOPPED, surely? I think you wantfrom main.time import Time, STOPPED. You could also make it aTimeclass attribute, so the test would becomeif time.status == Time.STOPPED:, further reducing ambiguity with the player version ofSTOPPED.import main.timetime.STOPPEDinstead ofSTOPPED, so that I won't get confused withplayer.STOPPED. The approach making it a class member sounds good to me - so I will either change my constants being inside of the class now, or rename them and put them into aconstantsmodule.timeare ambiguous (is it the current time, a time you are waiting for, ...) and also often used already -timeis the name of a standard module.