<html><body><div>I guess I am missing something big as I am looking for a shorthand way of doing the following:<br><br>           dctA = dict(x=x, y=y, ... n=n)<br><br>This is, as I understand it a very natural way of using a dictionary.  It seems that this syntax is unnecessarily redundant and hence my goal of writing something more compact.  Perhaps the way I am doing it is a little unorthodox, but the ultimate use of a dictionary is, as I understand it, completely in line with how dictionaries were designed to be used.  In my other code, I often use these dictionaries to pass arguments to functions and return results.  It allows me great flexibility without breaking existing code.  I pack a dictionary before passing and unpack when retrieving.  <br><br>I will give the locals approach a try, it seems a little more clumsy than simply passing the variables to the function.<br><br>Thanks again for your input.<br><br>---Andrew<br></div><div><br>On Apr 27, 2014, at 01:18 PM, Chris Angelico <rosuav@gmail.com> wrote:<br><br><div><blockquote type="cite"><div class="msg-quote"><div class="_stretch"><span style="white-space:pre;" data-mce-style="white-space: pre;">On Mon, Apr 28, 2014 at 4:56 AM, Andrew Konstantaras <<a href="mailto:akonsta@icloud.com" data-mce-href="mailto:akonsta@icloud.com">akonsta@icloud.com</a>  > wrote:<br>        > Thanks for the response and I can certainly see that this old code can be<br>        > improved, but I respectfully disagree on the utility of this function. The<br>        > flexibility of passing any number of arguments to the function and returning<br>        > a dictionary is much easier than writing out dict(x=x, y=y, ...n=n). I also<br>        > believe that "makeDict" makes my code very readable.<br><br>There is another option. You could pass a set of strings and a<br>dictionary of all locals, and have it fetch them. However, I<br>personally disagree about the readability; yes, it's nice and clean,<br>but it does something which 99% of Python programmers won't expect.<br>It's like writing a numeric type in C++ and then overloading the +<br>operator to concatenate the decimal representations.<br><br>        > My question is around finding the names of the variables passed to a<br>        > function from within the function. I have spent many hours looking on the<br>        > web looking for where in the frames and stacks this information is stored.<br>        > Does anyone have any insight where/how I can find the variables associated<br>        > with the arguments in<br>        ><br>        > dctA = makeDict(strA, intA)<br>        ><br>        > from within the function<br>        ><br>        > def makeDict(*args):<br>        > .... #need to find the variable names "strA" and "intA" in this<br>        > context<br><br>It isn't stored. What would be the names provided if, for instance, you do this:<br><br>dctA = makeDict("literal", intA + intB)<br><br>? There is no name for a literal or an expression. One of the<br>principles of Python is that an object is itself, regardless of the<br>name used to reference it. You're violating that by peeking into the<br>source code; you're fundamentally going against what every Python<br>programmer will expect.<br><br>Please don't do this. Take a step back, see what problem you're really<br>trying to solve, and solve that problem another way. Maybe a simple<br>DSL will help here, or possibly even just string interpolation,<br>depending on what you're trying to do. If you need help, show us some<br>of the code that uses makeDict, and we can advise.<br><br>Just please don't inflict makeDict onto any subsequent maintainer.<br><br>ChrisA<br>-- <br><a href="https://mail.python.org/mailman/listinfo/python-list" data-mce-href="https://mail.python.org/mailman/listinfo/python-list">https://mail.python.org/mailman/listinfo/python-list</a><br></span></div></div></blockquote></div></div></body></html>