[optparse] Problem with getting an option value

Lucas Malor 80xuuxk02 at sneakemail.com
Fri Apr 6 06:11:26 EDT 2007


Hello all. I'm trying to do a little script. Simply I want to make a list of all options with them default values. If the option is not specified in the command line, the script must try to read it in a config.ini file. If it's not present also there, it must set the default value.

The problem is I maked a simple list for this:

optname = [
  [ "delete", 	False ],
  [ "file", 	"file" ],
  [ "dir", 	"" ],

But I must check that the option was specified in command line:

(options, args) = parser.parse_args()
for opt in optname :
  if not options.opt[0] :
    # read the options from config.ini

The problem is options is an instance, so options."delete", for example, is wrong; I should pass options.delete . How can I do?



--------------------------------------
Protect yourself from spam, 
use http://sneakemail.com



More information about the Python-list mailing list