Python #ifdef

Benjamin Kaplan benjamin.kaplan at case.edu
Tue May 28 16:14:57 EDT 2013


On May 28, 2013 1:10 PM, "Carlos Nepomuceno" <carlosnepomuceno at outlook.com>
wrote:
>
> Thank you! I made it run like the following. What do you think about
that? IS there a better way?
>
>
>
> #The following runs on Python 2.7
> sc3='''
> # Python 3
> def original(n):
>     m = 0
>     for b in n.to_bytes(6, 'big'):
>         m = 256*m + b
>     return m
> '''
> if sys.version_info[0] == 3:
>     exec(sc3)
> --

No need for exec.

if sys.version_info[0] >= 3:
    def original(n) :
       ...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130528/84256d0d/attachment.html>


More information about the Python-list mailing list