Is vars() the most useless Python built-in ever?
Manolo Martínez
manolo at austrohungaro.com
Tue Dec 1 03:44:16 EST 2015
On 12/01/15 at 12:00pm, Steven D'Aprano wrote:
> I'm trying to understand why vars() exists. Does anyone use it?
Well, I have this little podcast aggregator
(https://github.com/manolomartinez/greg) that I and a bunch of other
people use. I started writing it some years ago, and the code is a bit
of a palimpsest, newer functionality reflecting my (somewhat) better
understanding of the language. One of the oldest bits is this main()
function:
def main(): # parse the args and call whatever function was selected
try:
args = parser.parse_args(sys.argv[1:])
args.func(vars(args))
except AttributeError as err:
if str(err) == "\'Namespace\' object has no attribute \'func\'":
parser.print_help()
else:
print("Something has gone wrong: {}".format(err), file = sys.stderr, flush = True)
To judge by this thread, this is probably wrong/noobish?
Cheers,
Manolo
More information about the Python-list
mailing list