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