Re: [Tutor] setting program configuration for all files and modules ofa program
>>> But to my optinion Config Parser offers the following advantage: >>> - Readable >>> - All are strings => no strange 'mysetting' is needed. >> I'm not sure what you mean. The Python variables and dictionary >> is all strings too. mysetting is just a string... > > He means, with ConfigParser strings don't need to be quoted, giving > perhaps a cleaner and more friendly syntax. Yes, Kent that's what I wanted to express. Thanks for clarifying. My target here are users that do not develop python. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] setting program configuration for all files and modules ofa program
"Kent Johnson" <[EMAIL PROTECTED]> wrote >> I'm not sure what you mean. The Python variables and dictionary >> is all strings too. mysetting is just a string... > > He means, with ConfigParser strings don't need to be quoted, giving > perhaps a cleaner and more friendly syntax. Ah, I see, yes that's a valid point. The whole issue of security is worth considering too. If the config file is not controlled then it is open to abuse since it allows a lot more than the simple set of name/value assignments that ConfigParser does. (I meant to mention that earlier) Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] setting program configuration for all files and modules ofa program
Alan Gauld wrote: >> But to my optinion Config Parser offers the following advantage: >> - Readable >> - All are strings => no strange 'mysetting' is needed. > > I'm not sure what you mean. The Python variables and dictionary > is all strings too. mysetting is just a string... He means, with ConfigParser strings don't need to be quoted, giving perhaps a cleaner and more friendly syntax. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] setting program configuration for all files and modules ofa program
"Tim Michelsen" <[EMAIL PROTECTED]> wrote >> import myconfig >> foo2 = myconfig.SectionFoo['second'] > This seems like reinventing what the ConfigParser > mdoule [1] already does. But with the advantage that its pure python, no parsing needed so its both faster and avouds any string to int type conversions > But to my optinion Config Parser offers the following advantage: > - Readable > - All are strings => no strange 'mysetting' is needed. I'm not sure what you mean. The Python variables and dictionary is all strings too. mysetting is just a string... But the choice is yours, you can use config parser to parse a config file into variables in a settings module or you can create the settings directly in the settings module. -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] setting program configuration for all files and modules ofa program
>>> Another option is to have the config settiongs in a normal >>> Python module and just import it. > >> I think that the cfg-files are much more readable for others. > > More readable than: > > # Section Heading > variable = value > > It looks pretty easy to read to me! :-) > > If its very complex you can use dictionaries: > > SectionFoo = { > firstName : theValue > second : anotherValue > } > > Which is still pretty easy for the casual reader/maintainer > and allows access like: > > import myconfig > foo2 = myconfig.SectionFoo['second'] This seems like reinventing what the ConfigParser mdoule [1] already does. I think I will read the config file once and the provide the parameters with a settings.py module throughout the program and the modules. Sounds like doing it twice. But to my optinion Config Parser offers the following advantage: - Readable - All are strings => no strange 'mysetting' is needed. Thanks for your help. Kind regards, Timmie [1]http://docs.python.org/lib/module-ConfigParser.html ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] setting program configuration for all files and modules ofa program
"Tim Michelsen" <[EMAIL PROTECTED]> wrote in >> Another option is to have the config settiongs in a normal >> Python module and just import it. > I think that the cfg-files are much more readable for others. More readable than: # Section Heading variable = value It looks pretty easy to read to me! :-) If its very complex you can use dictionaries: SectionFoo = { firstName : theValue second : anotherValue } Which is still pretty easy for the casual reader/maintainer and allows access like: import myconfig foo2 = myconfig.SectionFoo['second'] Just a thought. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] setting program configuration for all files and modules ofa program
> Yes, thats the way I'd recommend. >> Is there a more decent and elegant way? I don't know. I was just asking how other programmers achive this efficiently. > Another option is to have the config settiongs in a normal > Python module and just import it. That is less appealing if > the config file is shared with a non python program, but if > its all Python then that's a much simpler approach... I think that the cfg-files are much more readable for others. > PS. > Why all the parens around the error strings in your code? I am using gettext: _ = gettest.gettest Got this from the documentation. Thanks for your reply! Timmie ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] setting program configuration for all files and modules ofa program
"Tim Michelsen" <[EMAIL PROTECTED]> wrote > But I would like to modularize my code and separate the GUI code > from > the functional code that provides the calculation operations. This > will > help to expand the functionality at a later stage. I want to achieve > this through splitting the code into different modules. A good plan > How can I provide the settings stored in the configuration file > throughout my program to all functions without needing to initiate > the > ConfigParser object in each module? > > I through of having a special module "settings.py" which I could use > to > read in the configuration from the file and then import this in each > module. Yes, thats the way I'd recommend. > Is there a more decent and elegant way? Why do you feel that is "indecent" or inelegant? Another option is to have the config settiongs in a normal Python module and just import it. That is less appealing if the config file is shared with a non python program, but if its all Python then that's a much simpler approach... PS. Why all the parens around the error strings in your code? -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor