0

I have a program of this sort:

func1(**kwargs):

  for name, value in kwargs.items():

      print ("{} = {}".format(name, value))

I want the user to input the arguments. Something like this:

d={}
x = input("enter key and value separated by a space ")
y = x.split(' ')
d[y[0]] = y[1]

I tried storing the input as a dictionary and then passing it as an argument, - func1(d) - but it recognized the dictionary as one positional argument.

Does anyone have any ideas on how to do this?

  • Where is the input coming from, what does it look like, what are you actually trying to achieve, etc.? – TigerhawkT3 Oct 15 '16 at 01:07
  • How exactly are you calling your method. How do the arguments look like when you call `func1` – idjaw Oct 15 '16 at 01:07
  • I want it from the input() line. But that takes only strings. Something like this : x = input("Enter your first keyword argument. Separate the key and value with a space) Then I converted that x into a dictionary and passed it through to the function. – Mahima Singh Oct 15 '16 at 01:11
  • @MahimaSingh please do not post any updates to your question as a comment. Update your question with all relevant information. – idjaw Oct 15 '16 at 01:12
  • Briefly: if your function expects multiple keyword arguments instead of a single dictionary, you have to unpack that dictionary when you call the function as well: `func1(**d)`. – TigerhawkT3 Oct 15 '16 at 01:20

0 Answers0