![]() |
A one liner to dynamically "kwargify" your variables?
Does anyone know of a way to simply turn your variables in to the format of **kwargs?
I posted this code in the 500 Ways to Program Numbers 1 Through 10! thread a moment ago... :
def process(data_start, data_limit):Is there any way to replace the part highlighted red, so I don't have to restructure the dictionary? In other words, a way to "kwargify" a set of variables, or create a dictionary where each key is the name of the variable, and its value is its respective value? |
Not that I know of, but you can get all variables in a scope. Since all functions have their own own scope, and since create no new variables, your process function could be replaced with:
:
def process(data_start, data_limit)::
def process(data_start, data_limit): |
Well, the *args were there for the sake of having a more generalized function. But thanks.
|
**kwargs is just *argv[] worked over by someone trying to be original? Gotta love it. Now, if you'll excuse me, I'm going off to invent dirt.
|
Uh wow.
No, Dawei. Kwargs is commonly used. It stands for "KeyWordARGumentS". I'm not trying to be original. I'm not inventing anything. Even if I were, I wouldn't appreciate that comment either way. |
No, I think keyword args is a key value mapping, not an **argv. So its more like a dict, that's not a dict at the same time.
|
I know you didn't invent it. I see it in the docs all the time. The comment wasn't directed at Saney-baby, the center of the universe. Incidentally, I don't give a shit what you appreciate.
|
Uh wow... DaWei? I don't even know what to say...
I understand now that you were referring to the origination of the term kwargs. But would you be able to step back for a moment and see that you're quite out of line with whatever moment you were trailing off with in your last post? Okay fine, I give up... you win? :confused: Edit: @Arevos, I noticed you can call vars().clear() and that seems to destroy vars(). You can't see it anymore, even after assigning more variables. Out of curiosity, do you think that puts any limitations on Python from that point on in the code? Or is vars merely some sort of wrapper that has nothing to do with Python's internal functions? |
"Whatever moment" is just the moment that you think everything revolves around you. That's just your mom, son, not the rest of us.
|
Quote:
|
| All times are GMT -5. The time now is 1:52 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC