Iterating dictionary items + if statement results in problems
Mark Lawrence
breamoreboy at yahoo.co.uk
Mon Apr 15 07:25:36 EDT 2013
On 15/04/2013 11:50, Ombongi Moraa Fe wrote:
> hello Team,
>
> I have this fairly simple script to iterate the dictionary items and
> check if the items match certain values;
>
> dictionary={'1234567890':001, '0987654321':002}
> for k, v in dictionary.iteritems():
> .....
> ..... #suds client statements;
>
> if (k == '1234567890' and v == 001):
> criteria='Test'
> elif (k == '0987654321' and v == 002):
> criteria='Running'
> client.service.methodcall(value1,value2,criteria)
>
> During the first run of the dictionary items, the
> client.service.methodcall is called only once as expected; and a success
> initiation response is received from server. However, during the second
> run, the client.service.methodcall is called twice - when i check the
> log files, i see the client send request is done twice. Duplicate send
> requests of the same parameters results in a error in inititating a
> connection.
What makes you think there should be one call given the code above?
client.service.methodcall must be called for every loop iteration, so
there's one call with criteria 'test' and one with 'Running'. Note
there's no guarantee that the calls will always take place in the same
order. Slight aside there's no need for the round brackets in the if
and elif above.
>
> Someone please show me why my second run results in the
> client.service.methodcall() running twice. I can't seem to get a hang on
> it.
>
> Saludos
>
> Ombongi Moraa Faith
>
>
--
If you're using GoogleCrap™ please read this
http://wiki.python.org/moin/GoogleGroupsPython.
Mark Lawrence
More information about the Python-list
mailing list