Iterating dictionary items + if statement results in problems

Ombongi Moraa Fe moraa.lovetakes2 at gmail.com
Mon Apr 15 09:37:27 EDT 2013


Hello Team,

Thanks for your input.

|Possibly it's not matching because of your mistaken use of octal.  Octal
won't hurt for ints below 8, but you probably don't restrict it in the real
code.  For example,  v = 030 will not match equal in the following:

I've changed the key,value pairs in the dictionary because of privacy
commitment with my provider;

|My guess is that this is not your actual code at all, and you're trying to
"simplify" it for us.  You probably have more than |two items in the dict,
and one of them is NOT matching any of the if/elif tests.

            Currently, I only have 2 items in the dictionary. However, this
is a test environment and in the product environ, my items will be as many
as the number of services created on server for my connection. Currently,
the production has 10 services (key,value pairs)

I will only have a set number of key,value pairs and I cannot use other
items outside this range. The connection to providerr wouldn't be establish
for anything out of the allowed item ranges;

|That's not the whole script, since at the least, you need some code to
import or create client, value1 and value2.

The other portion of script to import the client and get values of
parameters value1 and value2 works well. I have tested the script without
using dictionaries by manually changing the items within the dictionary,
inside the code and it works successfully, establishing a connection for
both items; Now I need to iterate this for the sake of numerous items in
the production environment. And that's where I thought to bring in the if
statement.

|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.

Yes, I do understand that the items in the dictionary are not ordered. And
what I expect is "one call with criteria 'Test' and one with 'Running'. From
my logs file, the duplicate call always occurs at the last iteration of the
dictionary items.

In short, my problem arises after I include the if statement inside the
loop. I am new to python but I am pretty sure my program syntax is correct
here. If I run  a print statement instead of the
client.service.methodcall(value1,
value2), my output is just

Test
Running

2 of the services in the production environment will require the criteria
value. For the rest of the services, the method call will simply be

client.service.methodcall(value1, value2)

I need this criteria value in order to establish a service specific
connection for these 2 matching key,value pairs; instead of a generalised
connection as will be the case for any additional keys.this is where the
else default statement will come in later on. Right now I need to be able
to resolve the problem with my script as-it-is (with 2 dictionary items)

Thanks in advance.


Saludos

Ombongi Moraa Faith
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130415/07ab9252/attachment.html>


More information about the Python-list mailing list