Hello. I'm trying to make a simple language in Python. I have many functions, that handle arguments, and execute the commands. Although, the old way I was actually CALLING these functions was to have a dictionary of all the keywords to functions, and then get() it. Is these an easier way to do this?
Plazmotech 0 Newbie Poster
Recommended Answers
Jump to PostOne way is to register command handler functions with a decorator:
FUNCDICT = dict() def cmd_handler(func): assert func.__name__.endswith('cmd') FUNCDICT[func.__name__[:-3]] = func return func @cmd_handler def echocmd(...): ... @cmd_handler def catcmd(...): ... # etc
Functions are automatically added to FUNCDICT as you write them.
Did you read …
All 4 Replies
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
Plazmotech 0 Newbie Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
Gribouillis 1,391 Programming Explorer Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.