Not sure why my Markdown Here's splitting up my source :/ On Mon, Dec 4, 2017 at 10:13 AM Joe Weidenbach <[email protected]> wrote:
> Hmmm… Makes sense why you’d want this, but it appears that it’s not > available in Python 2.7 :( Python 3 on the other hand… > > > https://stackoverflow.com/questions/33048359/in-python-can-you-pass-variadic-arguments-after-named-parameters > > What you *could* do is something a little more explicit: > > Rig( > name='MyCharacter', > symmetry=True > > , > chains=( > Chain(name='Arm'), > Chain(name='Leg'), > ... > ) > ) > > This would, while adding a *bit* of cruft to the call, get around the > limitation. > > > On Mon, Dec 4, 2017 at 7:09 AM Marcus Ottosson <[email protected]> > wrote: > >> Hi all, >> >> I’m putting together a minor DSL whereby it’d be preferable to pass args >> *after* kwargs, like so. >> >> my_function(name="Marcus", True) >> >> This is normally a syntax error in Python.. >> >> SyntaxError: non-keyword arg after keyword arg >> >> But I’m not looking to actually *run* this, but rather get a dictionary >> out of it. Like an “argument signature definition” if you will. >> >> def my_function(*args, **kwargs): >> kwargs["children"] = args >> return kwargs >> >> Cosmetically, it’d looks something like this. >> >> Rig( >> Chain(name="Arm"), >> Chain(name="Leg"), >> >> name="MyCharacter", >> symmetry=True, >> ) >> >> But would make somewhat more sense to look at like this. >> >> Rig( >> name="MyCharacter", >> symmetry=True, >> >> Chain(name="Arm"), >> Chain(name="Leg"), >> ) >> >> I’ve tried passing it through ast, in the hopes that it’d look past this >> superficial syntax error, but alas it does not. >> >> import ast >> tree = ast.parse("""\ >> Rig( >> name="MyCharacter", >> symmetry=True, >> >> Chain(name="Arm"), >> Chain(name="Leg"), >> ) >> """) >> ast.dump(tree)# SyntaxError: non-keyword arg after keyword arg >> >> What I’d rather not do is get into manipulating text “by hand”, such >> writing it as the above, and then moving any line that looks like a keyword >> argument to the end of what looks like a closure; but if there’s nothing >> else that’s where I’m headed. >> >> I’d also not like to assume the exact look of any line, such as asserting >> that arguments are on a single line, as I can’t assume what the value of an >> argument might be. It may be another object with arguments of its own. >> >> Any ideas? >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Python Programming for Autodesk Maya" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD4B-Mu4D%2By97e7RgK8Zfiod3-ZqzTk5QXwnL2q4FHVpg%40mail.gmail.com >> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD4B-Mu4D%2By97e7RgK8Zfiod3-ZqzTk5QXwnL2q4FHVpg%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM33%3Da7jh0%2BPjA5-JcDMFWSB0U-BbZWfzP3WDapwuSw7kpYQ-w%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
