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


Groups > comp.lang.python > #46345

Re: Python #ifdef

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <joel.goldstick@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'url:pypi': 0.03; 'subject:Python': 0.06; 'must.': 0.07; 'lawrence': 0.09; 'developer': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; '<>.': 0.14; "wouldn't": 0.14; 'changes': 0.15; 'imposing': 0.16; 'pity': 0.16; 'possible?': 0.16; 'thread,': 0.16; 'wrote:': 0.18; 'module': 0.19; 'cc:addr:python.org': 0.22; 'unicode': 0.24; 'url:moin': 0.24; 'file.': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'wonder': 0.29; 'mix': 0.30; 'especially': 0.30; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; "skip:' 10": 0.31; 'url:wiki': 0.31; 'this.': 0.32; 'url:python': 0.33; 'maybe': 0.34; "i'd": 0.34; "can't": 0.35; 'received:209.85': 0.35; 'received:209.85.220': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'url:listinfo': 0.36; 'next': 0.36; "didn't": 0.36; 'url:org': 0.36; 'should': 0.36; 'so,': 0.37; 'received:209': 0.37; 'pm,': 0.38; 'url:mail': 0.40; 'read': 0.60; 'url:3': 0.61; 'skip:* 10': 0.61; "you're": 0.61; 'url:0': 0.67; 'to:addr:yahoo.co.uk': 0.84; 'carlos': 0.91; 'joel': 0.91; 'url:*': 0.95; 'subject: #': 0.96; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=MkfnnY1N8lAcQ3+U+mL0ZOLKIrq2XuS7fBPFwRBZfyo=; b=YqjFArUvfOxRTUD0ShBvPdHZHuDo71M+/O+i/WD5YyIObrHYlCuKws9+YNlA8FubjL WU2eRGqU5385xAjhEFA5gjqWzCj5Aa7feR8bwhgBeNOMkmmoSjUH9xkQ/IF579gfF9Yg Lp4IEmYKH7ua7sRcT1C1N8soAkQ7p00TE/IJgjNTRPEsjapT3k1JxMIJZc3OS6cY60uq QTIDV0HSX5JIkXqDAdkxufN5ttIGxPS5f9gYykuOioPWO0hMM+4OvALlVjcavq6Esk+1 3Rgep3uU/cmp27gA2IV/WE3zksTpM55uk0lFFQFY/9Rn3Yd2A1OcYjgXbldJJHAWH+qu lizg==
MIME-Version 1.0
X-Received by 10.52.164.211 with SMTP id ys19mr16503441vdb.102.1369779959161; Tue, 28 May 2013 15:25:59 -0700 (PDT)
In-Reply-To <ko3af7$ar9$1@ger.gmane.org>
References <BLU176-W12FAFEA3C7AFD687855E04D7970@phx.gbl> <ko3af7$ar9$1@ger.gmane.org>
Date Tue, 28 May 2013 18:25:59 -0400
Subject Re: Python #ifdef
From Joel Goldstick <joel.goldstick@gmail.com>
To Mark Lawrence <breamoreboy@yahoo.co.uk>
Content-Type multipart/alternative; boundary=001a11c24e12e2f27f04ddcebf49
Cc "python-list@python.org" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2330.1369779961.3114.python-list@python.org> (permalink)
Lines 103
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1369779961 news.xs4all.nl 15871 [2001:888:2000:d::a6]:56824
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:46345

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Tue, May 28, 2013 at 6:18 PM, Mark Lawrence <breamoreboy@yahoo.co.uk>wrote:

> On 28/05/2013 20:46, Carlos Nepomuceno wrote:
>
>> Are there Python 'preprocessor directives'?
>>
>> I'd like to have something like '#ifdef' to mix code from Python 2 and 3
>> in a single file.
>>
>> Is that possible? How?
>>
>>
> https://pypi.python.org/pypi/**six/1.3.0<https://pypi.python.org/pypi/six/1.3.0>
>
> --
> If you're using GoogleCrap™ please read this http://wiki.python.org/moin/*
> *GoogleGroupsPython <http://wiki.python.org/moin/GoogleGroupsPython>.
>
> Mark Lawrence
>
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>

my original response was from cell phone.  I just answered that you can't
do ifdefs, implying that there is no preprocessor in python.  I learned a
lot of things I didn't know reading the thread, but I wonder if it is a
good idea in general to try to write code like this.  -- combined 2.x/3.x
codebase can be a bear to maintain.  I wouldn't do it unless there was some
imposing reason that I must.  Its not just print() -- that isn't bad, but
changes in module names (urllib), arithmetic, and unicode especially make
this idea in general, very tricky.  Pity the next developer who needs to
try to maintain it.

So, maybe you CAN do it, but SHOULD you want to do it?

-- 
Joel Goldstick
http://joelgoldstick.com

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


Thread

Re: Python #ifdef Joel Goldstick <joel.goldstick@gmail.com> - 2013-05-28 18:25 -0400
  Supporting both 2.x and 3.x in one code base [was Re: Python #ifdef] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-29 00:57 +0000

csiph-web