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


Groups > comp.lang.python > #12459

Re: Handling 2.7 and 3.0 Versions of Dict

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Handling 2.7 and 3.0 Versions of Dict
Date 2011-08-30 23:33 -0400
References <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.591.1314761672.27778.python-list@python.org> (permalink)

Show all headers | View raw


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

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


Thread

Handling 2.7 and 3.0 Versions of Dict Travis Parks <jehugaleahsa@gmail.com> - 2011-08-30 18:43 -0700
  Re: Handling 2.7 and 3.0 Versions of Dict Terry Reedy <tjreedy@udel.edu> - 2011-08-30 23:33 -0400
  Re: Handling 2.7 and 3.0 Versions of Dict "Martin v. Loewis" <martin@v.loewis.de> - 2011-08-31 11:55 +0200
    Re: Handling 2.7 and 3.0 Versions of Dict Ian Kelly <ian.g.kelly@gmail.com> - 2011-08-31 09:44 -0600
      Re: Handling 2.7 and 3.0 Versions of Dict Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-09-01 11:37 +1200
        Re: Handling 2.7 and 3.0 Versions of Dict Travis Parks <jehugaleahsa@gmail.com> - 2011-08-31 18:28 -0700
          Re: Handling 2.7 and 3.0 Versions of Dict "Gabriel Genellina" <gagsl-py2@yahoo.com.ar> - 2011-09-02 13:36 -0300
            Re: Handling 2.7 and 3.0 Versions of Dict Travis Parks <jehugaleahsa@gmail.com> - 2011-09-02 09:53 -0700
              Re: Handling 2.7 and 3.0 Versions of Dict Terry Reedy <tjreedy@udel.edu> - 2011-09-02 16:22 -0400
              Re: Handling 2.7 and 3.0 Versions of Dict "Gabriel Genellina" <gagsl-py2@yahoo.com.ar> - 2011-09-02 17:29 -0300

csiph-web