<div dir="ltr"><br><br><div class="gmail_quote">On Fri, Aug 29, 2008 at 12:20 PM, Kent Johnson <span dir="ltr">&lt;<a href="mailto:kent37@tds.net">kent37@tds.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On Fri, Aug 29, 2008 at 9:49 AM, eShopping<br>
&lt;<a href="mailto:etrade.griffiths@dsl.pipex.com">etrade.griffiths@dsl.pipex.com</a>&gt; wrote:<br>
&gt; Hi<br>
&gt;<br>
&gt; I have a GUI program that extracts some information from the user as<br>
&gt; strings, and I then want to use the strings to form an argument list to<br>
&gt; another function. &nbsp;Hopefully the following code gives some flavour:<br>
&gt;<br>
&gt; def myfunc(**kwargs):<br>
&gt; &nbsp; &nbsp;while kwargs:<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;name, value = kwargs.popitem()<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;print name, value<br>
&gt;<br>
&gt; myfunc(a=1, b=2, c=3, d=4)<br>
&gt; arg_str = &quot;a=1, b=2, c=3, d=4&quot;<br>
&gt; myfunc(arg_str)<br>
&gt;<br>
&gt; ARG_STR will be built up from the data extracted from the GUI. &nbsp;I get this<br>
&gt; error<br>
&gt;<br>
&gt; TypeError: myfunc() takes exactly 0 arguments (1 given)<br>
&gt;<br>
&gt; I understand that ARG_STR is a string and that MYFUNC is expecting something<br>
&gt; else ,,, but not sure what it is. &nbsp;I have tried various dictionary<br>
&gt; configurations such as<br>
&gt;<br>
&gt; arg1 = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;]<br>
&gt; arg2 = [1,2,3,4]<br>
&gt; arg3 = dict(zip(arg1,arg2))<br>
&gt; myfunc(arg3)<br>
</div></blockquote><div><br>&nbsp;myfunc(**arg3)<br>&nbsp;<br>Let&#39;s back up to arg_str = &quot;a=1, b=2, c=3, d=4&quot;<br><br>To create a dictionary from that:<br></div></div><br>argDict = dict(pair.split(&#39;=&#39;) for pair in arg_str.split(&#39;,&#39;))<br>
<br>If there is no compelling requirement that myfunc&#39;s argument be in the form **kwargs then<br><br>def myfunc(kwargs):<br> &nbsp;&nbsp;&nbsp; while kwargs:<br>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; name, value = kwargs.popitem()<br>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; print name, value<br><br>myfunc(argDict)<br><br>-- <br>Bob Gailer<br>919-636-4239<br>
</div>