Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!news2.euro.net!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.025 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.01; 'that?': 0.05; 'subject:Python': 0.06; 'received:209.85.219': 0.09; 'runs': 0.10; 'python': 0.11; 'def': 0.12; '2.7': 0.14; "'''": 0.16; 'to:name:python list': 0.16; 'wrote:': 0.18; '>': 0.26; 'header :In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'way?': 0.31; 'run': 0.32; 'received:209.85': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'received:209': 0.37; 'thank': 0.38; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'skip:\xc2 10': 0.60; 'skip:n 10': 0.64; '8bit%:100': 0.72; 'subject: #': 0.96; '2013': 0.98 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:x-gm-message-state; bh=huO4TmUU6u48aCX/Smc7TKzbT9ABkXOcV3OUawZBj3U=; b=Kj5HnSPr9fb5PtrsLsZUErecKK6PYO8cnTBRd9fpUsPUGuNEQx6N/uklUwFntdarIu hPLDOl8AFD0Niu11vGB5KgEvQviXpLmrKbY/infu/o5JQblTasOsEGQiUvKz3HyRVtN1 HvEJ7rCfkmTL31ssjKTiwrgPKEObJ6cglId3x9IvQ+c73qxD3BHVPVabdZO6intEKCbT QdUlAOyMH8bpxJoGRQc7mbUji8oHJ0y0rMI+a69PSb6k6YKiR59IdLMj+tdZaufJ9SsS RUSPCSpG+GVjUpxDEpGoy5tuV6lYR9A6ieguKS/Latoqf5RY8+2Hl9a7KCfTyd3QSuFo 0TKA== X-Received: by 10.182.45.231 with SMTP id q7mr22012665obm.58.1369772097879; Tue, 28 May 2013 13:14:57 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.182.45.231 with SMTP id q7mr22012655obm.58.1369772097752; Tue, 28 May 2013 13:14:57 -0700 (PDT) In-Reply-To: References: Date: Tue, 28 May 2013 13:14:57 -0700 Subject: RE: Python #ifdef From: Benjamin Kaplan To: Python List Content-Type: multipart/alternative; boundary=047d7b67785a4faf4f04ddcceb2b X-Gm-Message-State: ALoCoQlFJAP150zDjaUSH78WRv3x94PiA0ICQr/0LcbjqTkSHfkTyKxuYN46AXDgikweOVZXf9cXRnYpJbbMhqz/hRGSWXnBGV9y9UgJohxx3AN/ksz6N1gJZkX5tNEMpKUQKXGMiPIYylMYkUrVPNbNdO4oMfldwA== X-Junkmail-Whitelist: YES (by domain whitelist at mpv2.tis.cwru.edu) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 63 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369772484 news.xs4all.nl 15973 [2001:888:2000:d::a6]:41734 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46335 --047d7b67785a4faf4f04ddcceb2b Content-Type: text/plain; charset=UTF-8 On May 28, 2013 1:10 PM, "Carlos Nepomuceno" 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) : ... --047d7b67785a4faf4f04ddcceb2b Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


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

No need for exec.

if sys.version_info[0] >=3D 3:
=C2=A0=C2=A0=C2=A0 def original(n) :
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ...

--047d7b67785a4faf4f04ddcceb2b--