Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; '2.7': 0.04; 'sys': 0.05; 'received:verizon.net': 0.07; 'terry': 0.07; 'python': 0.08; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'subject:2.7': 0.09; 'def': 0.15; 'library': 0.15; '2to3': 0.16; 'dictionaries': 0.16; 'distinct,': 0.16; 'parks': 0.16; 'reedy': 0.16; 'travis': 0.16; 'wrote:': 0.16; 'language': 0.17; 'jan': 0.19; 'wrote': 0.20; 'header:In-Reply-To:1': 0.22; 'pm,': 0.24; 'code': 0.25; 'problem': 0.28; 'import': 0.28; 'ran': 0.30; 'translate': 0.31; 'version': 0.32; 'values': 0.32; 'to:addr :python-list': 0.33; 'calling': 0.33; 'header:User-Agent:1': 0.34; 'algorithms': 0.34; 'header:X-Complaints-To:1': 0.35; 'received:org': 0.38; 'some': 0.38; 'subject:: ': 0.39; 'under': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'you.': 0.62; 'alternative': 0.64; 'here': 0.65; 'hood.': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Handling 2.7 and 3.0 Versions of Dict Date: Tue, 30 Aug 2011 23:33:37 -0400 References: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-74-109-121-73.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20110812 Thunderbird/6.0 In-Reply-To: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314761672 news.xs4all.nl 2503 [2001:888:2000:d::a6]:60539 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12459 On 8/30/2011 9:43 PM, Travis Parks wrote: > I am writing a simple algorithms library that I want to work for both > Python 2.7 and 3.x. I am writing some functions like distinct, which > work with dictionaries under the hood. The problem I ran into is that > I am calling itervalues or values depending on which version of the > language I am working in. Here is the code I wrote to overcome it: > > import sys > def getDictValuesFoo(): > if sys.version_info< (3,): > return dict.itervalues > else: > return dict.values One alternative is to use itervalues and have 2to3 translate for you. -- Terry Jan Reedy