Yes—the answer to the problem is right there in the question itself. Please 
avoid using Python reserved keywords such as class as identifiers. Your 
argparse code has in fact worked correctly: it successfully created an 
attribute named class on the args object, but you cannot access it using dot 
notation. As is obvious, attempting args.class results in SyntaxError: invalid 
syntax.

At the same time, you can verify that the argument does exist by inspecting 
(Pdb) vars(args), which shows {'class': 'address'}. The solution is 
straightforward: avoid using reserved keywords. You can use an alias such as 
cls to resolve this issue.
-- 
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to