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


Groups > comp.lang.python > #43617

Re: Iterating dictionary items + if statement results in problems

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'parameters': 0.04; 'elif': 0.05; 'duplicate': 0.07; 'subject: + ': 0.07; 'tests.': 0.07; 'currently,': 0.09; 'iterate': 0.09; 'run,': 0.09; 'sure,': 0.09; '"test"': 0.16; 'exactly?': 0.16; 'initiation': 0.16; 'octal': 0.16; 'received:74.208.4.195': 0.16; 'script,': 0.16; 'statements;': 0.16; 'subject:problems': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'all,': 0.19; 'trying': 0.19; 'items.': 0.19; 'import': 0.22; 'team,': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'fairly': 0.24; 'server.': 0.24; 'script': 0.25; 'order.': 0.26; 'possibly': 0.26; 'second': 0.26; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'am,': 0.29; "doesn't": 0.30; 'matching': 0.30; 'restrict': 0.30; 'code': 0.31; 'requests': 0.31; "skip:' 10": 0.31; 'prints': 0.31; 'probably': 0.32; 'run': 0.32; 'running': 0.33; 'guess': 0.33; 'actual': 0.34; 'skip:d 20': 0.34; "can't": 0.35; 'something': 0.35; 'equal': 0.35; 'but': 0.35; 'add': 0.35; 'there': 0.35; 'done': 0.36; 'example,': 0.37; 'two': 0.37; 'to:addr:python-list': 0.38; 'that,': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'called': 0.40; 'success': 0.61; 'simple': 0.61; "you're": 0.61; 'first': 0.61; "you'll": 0.62; 'show': 0.63; 'real': 0.63; 'happen': 0.63; 'more': 0.64; 'hang': 0.67; 'received:74.208': 0.68; 'reverse': 0.68; 'results': 0.69; 'connection.': 0.74; 'repeat': 0.74; '.....': 0.78; 'dict,': 0.84; 'mistaken': 0.84; 'items,': 0.91; 'subject:results': 0.91; 'thing,': 0.91
Date Mon, 15 Apr 2013 08:09:16 -0400
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4
MIME-Version 1.0
To python-list@python.org
Subject Re: Iterating dictionary items + if statement results in problems
References <CAM6w3nroUKz5GZua_bZ8A5HdsWdhK0yOcjz4XQYJdoGjVpqmOw@mail.gmail.com>
In-Reply-To <CAM6w3nroUKz5GZua_bZ8A5HdsWdhK0yOcjz4XQYJdoGjVpqmOw@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:TPKfU6YofsKOLaYeDtMzXtIbiU4g+odIGIeXZiAIAPE R6a2b3iM9sOJ/p9MNKvrrUU5fnV6M33qE8aN4eoJNwh72wi4/g y5OGMqLT03vsHHGyybSTh2ucNzErRlwtiCXH8y7q86Xj7jRW2G 4nYPwBV6ThovhNb2ROfww751c5z7UVfHz+bOq92U6xAMbmGacr YuAI7CAaDLZg5my/pm8uSahMYkQDFNA5XhBoFTWW80dtGHNENH 1UFlPggRmRUB/PxpsZ5D0yKwrRQqLie+VotQM+2/SPY4IJdPVm Z9bSq3wkXCPalQxY/SGEDMLMrBRK3TAuE3IGlXVwQDO6eOojw= =
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.629.1366027783.3114.python-list@python.org> (permalink)
Lines 63
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1366027783 news.xs4all.nl 2646 [2001:888:2000:d::a6]:40576
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:43617

Show key headers only | View raw


On 04/15/2013 06:50 AM, 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)
>
>

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

>
> During the first run of the dictionary items,

What do you mean by that, exactly?  Do you mean the first time around 
the loop?  Or the first time the script is run?  Or what?

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

Why not take out the middleman, and just add some prints in the loop?  I 
don't see any point in the loop;  if you're sure there are exactly two 
items in the dict, just process those two items.  If you're not sure, 
what do you want to happen when you encounter something that doesn't 
match either the if or the elif.  Currently, you'll just repeat the last 
methodcall.

One final thing, a dict's order is not promised.  So you may process 
these items in either as "Test" and "Running", or in the reverse order.

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. 
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:
      elif v == 30:



-- 
DaveA

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


Thread

Re: Iterating dictionary items + if statement results in problems Dave Angel <davea@davea.name> - 2013-04-15 08:09 -0400

csiph-web