You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@response_to(r"(?P<first_name>.+) (?P<last_name>.+)")defget_name(message, first_name, last_name):
message.reply(f"Your name is {first_name}{last_name}.")
>>>"Your name is Lena Smith."
or
@response_to(r"(?P<first_name>.+) (?P<last_name>.+)")defget_name(message, *args):
message.reply(f"Your name is {args[0]}{args[1]}.")
>>>"Your name is Lena Smith."
or
@response_to(r"(?P<first_name>.+) (?P<last_name>.+)")defget_name(message, *args):
keys= ["first_name", "last_name"]
kwargs=dict(zip(keys, args))
message.reply(f"Your name is {kwargs["first_name"]}{kwargs ["last_name"]}.")
>>>"Your name is Lena Smith."
Expected Behavior
@response_to(r"(?P<first_name>.+) (?P<last_name>.+)")defget_name(message, **kwargs):
message.reply(f"Your name is {kwargs['first_name']}{kwargs['last_name']}.")
>>>"Your name is Lena Smith."
The text was updated successfully, but these errors were encountered:
sheiun
changed the title
Regex group name as arguments name
[Feature Request] Regex group name as arguments name
Oct 27, 2019
However, there are still edge cases such as: r"(?P<first_name>.+) (.+) (?P<last_name>.+)" where combining position and name based arguments will cause problems. The function would need a signature such as def hello(middle_names, first_name, last_name)
Revisiting this issue, I don't think we can implement the above without properly handling the edge cases mentioned.
This would actually make the code quite more complex.
If anything, we need a more sophisticated parser for complex cases. parsy has proved reliable on my personal uses. Something for another pull-request/improvement.
I would vote to close this as wontfix. @attzonko your take on it?
Current Behavior
or
or
Expected Behavior
The text was updated successfully, but these errors were encountered: