Skip to main content
added 312 characters in body
Source Link

Zen of python says "Namespaces are one honking great idea -- let's do more of those!".

Implies the following is pythonic.

do_thing(vars.important_value)

When we include the import of vars as a module in our example; did the pythonic nature change? Isis this still pythonic? (I would say it is)

import vars
do_thing(vars.important_value)

How about if we change how it's imported? Isimported; is it still pythonic? (again, I'd say yes)

from some_module import vars
do_thing(vars.important_value)

How about when we use an instance of a class?

class Vars:
    def __init__(iv):
        self.important_value = iv
vars = Vars(1234)

do_thing(vars.important_value)

That last bit is what got me. If instantiating a class is the key to creating a namespace outside of a module in order be pythonic, that would seem to contradict "simple is better"

It's for this reason I say using aan uninstantiated class in this manneras a namespace is indeed pythonic, even if not often used.

Zen of python says "Namespaces are one honking great idea -- let's do more of those!".

Implies the following is pythonic.

do_thing(vars.important_value)

When we include the import of vars as a module in our example; did the pythonic nature change? Is this still pythonic? (I would say it is)

import vars
do_thing(vars.important_value)

How about if we change how it's imported? Is it still pythonic? (again, I'd say yes)

from some_module import vars
do_thing(vars.important_value)

It's for this reason I say using a class in this manner is pythonic, even if not often used.

Zen of python says "Namespaces are one honking great idea -- let's do more of those!".

Implies the following is pythonic.

do_thing(vars.important_value)

When we include the import of vars as a module in our example; is this still pythonic?

import vars
do_thing(vars.important_value)

How about if we change how it's imported; is it still pythonic?

from some_module import vars
do_thing(vars.important_value)

How about when we use an instance of a class?

class Vars:
    def __init__(iv):
        self.important_value = iv
vars = Vars(1234)

do_thing(vars.important_value)

That last bit is what got me. If instantiating a class is the key to creating a namespace outside of a module in order be pythonic, that would seem to contradict "simple is better"

It's for this reason I say using an uninstantiated class as a namespace is indeed pythonic, even if not often used.

Source Link

Zen of python says "Namespaces are one honking great idea -- let's do more of those!".

Implies the following is pythonic.

do_thing(vars.important_value)

When we include the import of vars as a module in our example; did the pythonic nature change? Is this still pythonic? (I would say it is)

import vars
do_thing(vars.important_value)

How about if we change how it's imported? Is it still pythonic? (again, I'd say yes)

from some_module import vars
do_thing(vars.important_value)

It's for this reason I say using a class in this manner is pythonic, even if not often used.