0

I am new to python coding .I have done a soap client program in php but now i want to convert it in python

I am stuck at this point

$result = $client->GetLastData(array('Id' => array($id)));

How can i convert this set of code from php to python. Can any one please tell me is there an way to pass an associative arrays in python

Thanks in advance

Ashith
  • 309
  • 1
  • 3
  • 17
  • 1
    Hi this answer could help you http://stackoverflow.com/questions/9495950/how-to-implement-associative-array-not-dictionary-in-python (possible duplicate) – rsz Oct 20 '15 at 11:51

1 Answers1

2

There is nothing special you really have to do. If you have an associative array like this (In Python called a dictionary):

a = {
    "id": [1234567, 55555, 4444444]
}

And you want to pass your dictionary (associative array) the way you are trying to do in your example, you just need to do this:

GetLastData(a)

If you are looking to pass specific data from your associative array / dictionary, then you can do this:

GetLastData(a.get("id"))

or

GetLastData(a["id"])

I would suggest using get as the default return will be None if the "id" key is not found. If you access with the "square brackets", it would throw a key error, and you would have to handle accordingly.

idjaw
  • 25,487
  • 7
  • 64
  • 83