[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-3000
Subject:    Re: [Python-3000] interaction between locals,
From:       Nick Coghlan <ncoghlan () gmail ! com>
Date:       2007-07-27 10:20:09
Message-ID: 46A9C6D9.3050405 () gmail ! com
[Download RAW message or body]

Lisandro Dalcin wrote:
> I think it should work in any 2x and 3K. Is this right? Perhaps this
> trick could be used for some automated conversion tool targeting
> backward compatibility with 2.x series.

The backwards compatible version looks like this:

     def __iter__(self):
          if self == _mpi.INFO_NULL:
              return
          nkeys = _mpi.info_get_nkeys(self)
          for nthkey in xrange(nkeys):
              yield _mpi.info_get_nthkey(self, nthkey)

The 2to3 converter will automatically convert the xrange() call to a 
range() call for the Py3k version.

If you want to persist in trying to get the same code running on both 
Py3k and 2.x without using the 2->3 converter, then I suggest 
segregating it all into a compatibility module and do:

   from py3k_compat import _range

The try/except code to determine how to set _range would then occur only 
once, regardless of the number of places where you used it.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan@gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: http://mail.python.org/mailman/options/python-3000/python-3000%40progressive-comp.com
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic