Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43624

Re: Iterating dictionary items + if statement results in problems

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <moraa.lovetakes2@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'parameters': 0.04; 'syntax': 0.04; 'output': 0.05; 'duplicate': 0.07; 'subject: + ': 0.07; 'tests.': 0.07; 'currently,': 0.09; 'items)': 0.09; 'iterate': 0.09; 'received:209.85.219': 0.09; 'sake': 0.09; 'python': 0.11; "wouldn't": 0.14; 'above?': 0.16; 'dictionaries': 0.16; 'dictionary,': 0.16; 'dictionary.': 0.16; 'items;': 0.16; 'iteration': 0.16; 'iteration,': 0.16; 'loop.': 0.16; 'octal': 0.16; 'pairs': 0.16; 'range.': 0.16; 'script,': 0.16; 'statement.': 0.16; 'subject:problems': 0.16; 'to:addr:web.de': 0.16; '\xa0you': 0.16; 'code.': 0.18; 'all,': 0.19; 'trying': 0.19; 'advance.': 0.19; 'file,': 0.19; 'items.': 0.19; 'value.': 0.19; 'later': 0.20; 'import': 0.22; 'portion': 0.22; 'team,': 0.22; 'print': 0.22; 'environment': 0.24; "i've": 0.25; 'script': 0.25; 'order.': 0.26; 'values': 0.27; 'correct': 0.29; 'rest': 0.29; 'matching': 0.30; 'restrict': 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'occurs': 0.31; 'saludos': 0.31; 'probably': 0.32; 'skip:c 30': 0.32; 'run': 0.32; 'running': 0.33; 'guess': 0.33; 'actual': 0.34; 'problem': 0.35; 'received:209.85': 0.35; 'connection': 0.35; 'created': 0.35; 'equal': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'method': 0.36; 'thanks': 0.36; 'should': 0.36; 'changing': 0.37; 'example,': 0.37; 'received:209': 0.37; 'server': 0.38; 'to:addr:python-list': 0.38; 'anything': 0.39; 'expect': 0.39; 'skip:& 20': 0.39; 'environment.': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'called': 0.40; 'logs': 0.60; 'manually': 0.60; 'new': 0.61; 'establish': 0.61; 'privacy': 0.61; 'services,': 0.61; 'simply': 0.61; "you're": 0.61; 'guarantee': 0.63; 'real': 0.63; 'more': 0.64; 'to:2**2': 0.65; 'within': 0.65; 'services': 0.66; 'production': 0.68; 'default': 0.69; 'connection.': 0.74; '"one': 0.84; "'test'": 0.84; 'dict,': 0.84; 'mistaken': 0.84; 'ordered.': 0.84; 'short,': 0.84; 'to:addr:yahoo.co.uk': 0.84; '|what': 0.84; '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0': 0.84; 'faith': 0.91; 'subject:results': 0.91; 'numerous': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:from:date:message-id:subject:to :content-type; bh=BJit8VBP/Eh4Gu7sT76kSIAi9bNHKGNNJRRIaI/hAns=; b=K14Jl4AcXdRoJcq0CtI7VpwqxJUJuuyLQ3p0F8bL9dzJA+93Sgpj3Y0s19hLd1H1yi un9N21Xjzyj2J5RHocE1Pv0UbU/F9AbcFBAqxBtZ3OzmWqgcLo9+Ixky9VNYZN5Vlcxd pCChvn8Zi/hvAYsAm23A5cETVqPoa+dgS2h4uTVvBMxma0XGMIBv4LNohWxac9Yz10rz Zcz/o1BKH/EvyP1BHObtdrZAEM4U3Bt+H4x2ot1FLvKTn2OY4MyBEbesUkSxy6gCaq/i 0hJQ+CiPfszV163VcoxeYsKgnpZyCTDIX/rTntsKEaI5NKo14JZ8xHeZda7PkOB6ETSJ Lb7Q==
X-Received by 10.60.135.103 with SMTP id pr7mr7368357oeb.142.1366033087282; Mon, 15 Apr 2013 06:38:07 -0700 (PDT)
MIME-Version 1.0
From Ombongi Moraa Fe <moraa.lovetakes2@gmail.com>
Date Mon, 15 Apr 2013 16:37:27 +0300
Subject Re: Iterating dictionary items + if statement results in problems
To python-list@python.org, Mark Lawrence <breamoreboy@yahoo.co.uk>, Peter Otten <__peter__@web.de>, Dave Angel <davea@davea.name>
Content-Type multipart/alternative; boundary=047d7b417c7deb450404da665c64
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.633.1366033096.3114.python-list@python.org> (permalink)
Lines 179
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1366033096 news.xs4all.nl 2628 [2001:888:2000:d::a6]:39774
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:43624

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Iterating dictionary items + if statement results in problems Ombongi Moraa Fe <moraa.lovetakes2@gmail.com> - 2013-04-15 16:37 +0300

csiph-web