Peter. Good afternoon. On Mon, 29 Dec 2025 10:54:33 +0100 "Peter J. Holzer" <[email protected]> wrote:
> On 2025-12-29 11:28:27 +0200, Schimon Jehudah via Python-list wrote: > > Greetings, one and all. > > > > I am experimenting with module argparse. > > > > I would be glad to know of your opinions about this concern. > > > > Notice dest="class". > > Your problem has nothing to do with argparse. This is a property of > the Python language itself. > Yes, so I realized. > > > Python software > > --------------- > > > > from argparse import ArgumentParser > > parser = ArgumentParser(description="Slixfeed OSTN news service > > setup.") > > > > parser.add_argument( > > "--class", > > choices=["address", "hostname", "tld"], > > dest="class") > > args = parser.parse_args() > > breakpoint() > > > > > > Execute the software > > -------------------- > > > > -> breakpoint() > > (Pdb) args.class > > *** SyntaxError: invalid syntax > > (Pdb) > > `class` is a keyword in Python. You can't use `class` where a variable > name or other identifier is expected. > > You can access attributes with arbitrary names with getattr: > > (Pdb) p getattr(args, "class") > None > Thank you for this information. > > But I would not recommend that. Use a non-reserved name instead. > Maybe `feed_class`. Or just `class_`, if you really don't want to be > more specific what kind of class it is. > I changed it to "kind". https://git.xmpp-it.net/sch/Slixfeed/src/branch/master/src/slixfeed/script/setup.py Regards, Schimon -- https://mail.python.org/mailman3//lists/python-list.python.org
