1

In Python 2.7, I am trying to set a class variable based on static methods.

class Params(object):

    DEFAULT_PATH = Params._set_default_path()

    @staticmethod
    def _set_default_path():
        return os.path.expanduser(
            "~/prod") if Params._is_host_in_prod() else os.path.expanduser(
            "~/qa")

    @staticmethod
    def _is_host_in_prod():
       return True # always prod, example code

when I execute the code, I get NameError: name 'Params' is not defined, what's the Pythonic way to do it?

2
  • I found this answer: stackoverflow.com/a/16456924/12946233 What do you think about it? Commented Apr 14, 2020 at 8:31
  • I think this is helpful Commented Apr 15, 2020 at 0:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.