optparse object population

Jeff Epler jepler at unpythonic.net
Wed Aug 4 21:25:35 EDT 2004


You could create a subclass of Option, overriding take_action() with a
new "store_attr" action, which would do something along the lines of

    def take_action(self, action, dest, opt, value, values, parser):
        raise RuntimeError, "untested code follows"
        if action == 'store_attr':
            objname, attr = dest.split(",", 1)
            obj = getattr(values, objname)
            setattr(obj, attr, value)
            return 1
        return Option.store_attr(self, action, dest, opt, value, values, parser)

or you could probably use "callback" in some way.

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20040804/a5a6c022/attachment.sig>


More information about the Python-list mailing list