Lacrima wrote:
Hello!

I am newbie in python and I have really simple question, but I need
your advice to know how to do best.
I need to store a number of dictionaries in certain place. I've
decided to store them in a separate module.
Like this:
dicts.py
-----------------------
dict1 = {....}
dict2 = {....}
dict3 = {....}

Then, when I need any dictionary, I can access it:
import dicts
dicts.dict1

Is it a good practice? Or should I store them as class attributes or
anything else?

Thanks in advance.

With regards, Max
(sorry if my English isn't very proper)
Defining dict as a module attribute ic correct, but try to answer the following question:

Is dict1 an attribute/property/declension of the object/entity defined by the module dicts ?
If yes, then your design is correct.

An correct example:
fruits.py
------------
apple = {}
banana = {}

An incorrect one:
fruit.py
-----------
apple={}
bicycle={}

Basically, the rule is very straightforward, set your dict as a module attribute only if its one of its attribute (very nice paraphrase !) Most of people (including me) tend to have a module, where they put everything they have no idea about their location. This is a bad habit and result from a uncontrolled/undocumented design. Usually documenting objects in such modules is really painful.

Your proposal is fine from a python syntax point of view. I can't tell of your design with names like (dicts.py and dict1,dict2) hoping you do not intend to name them that way.

JM
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to