Should I use a class in this: Reading a XML file using lxml.
Posted
by PulpFiction
on Stack Overflow
See other posts from Stack Overflow
or by PulpFiction
Published on 2010-06-15T12:25:02Z
Indexed on
2010/06/15
13:02 UTC
Read the original article
Hit count: 153
python
|design-patterns
Hi everyone.
This question is in continuation to my previous question, in which I asked about passing around an ElementTree.
I need to read the XML files only and to solve this, I decided to create a global ElementTree and then parse it wherever required.
My question is:
Is this an acceptable practice? I heard global
variables are bad. If I don't make it global
, I was suggested to make a class
. But do I really need to create a class
? What benefits would I have from that approach. Note that I would be handling only one ElementTree instance per run, the operations are read-only. If I don't use a class
, how and where do I declare that ElementTree so that it available globally? (Note that I would be importing this module)
Please answer this question in the respect that I am a beginner to development, and at this stage I can't figure out whether to use a class or just go with the functional style programming approach.
© Stack Overflow or respective owner