On 2015-01-27 16:10, Steven D'Aprano wrote:
On Tue, Jan 27, 2015 at 08:39:17AM -0800, Alex Kleider wrote:

I use the docopt module to collect command line options and then
configparser to read a file.
Some of the values (such as a port number, for example) must then be
adjusted.  An example is
a port number which I want to convert from "5022" to ":5022" if it's a
non standard port or
to "" if it is the standard "22" so it can then be used as a string
format parameter.
Perhaps I should be doing this in the same place as I set up the string
rather than where
I populate the 'config' and 'PARAMS' dictionaries?


I see the basic problem as this:

- you have config settings (command line options, config files)
  which by their nature are always strings
- furthermore they are strings in a format designed for human use
  rather than machine use
- by the time your function uses them, they need to be converted
  from human-format to machine-format.

That last step might involve a type conversion like int(s), trimming
whitespace, or more complex operations.

The most obvious way to do them is to apply the operation after reading
the config value but before storing it in the params dict. If that
works, I wouldn't add complexity where it isn't needed.

If it doesn't work for you, I think you need to explain what the problem
is before we can suggest a better design.

Again, thank you very much.
I'll do as you suggest above and see if I can make it work.
Alex
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to