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.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'cpython': 0.05; 'subject:Python': 0.06; 'compile-time': 0.09; 'python': 0.11; '2.7': 0.14; '__future__': 0.16; 'possible?': 0.16; 'received:74.208.4.195': 0.16; 'statement)': 0.16; 'variables,': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'module': 0.19; 'import': 0.22; 'header:User-Agent:1': 0.23; 'file.': 0.24; 'define': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'thus': 0.29; "doesn't": 0.30; 'mix': 0.30; 'code': 0.31; "skip:' 10": 0.31; '3.x': 0.31; 'quite': 0.32; 'checking': 0.33; "i'd": 0.34; 'something': 0.35; 'objects': 0.35; 'but': 0.35; 'there': 0.35; 'doing': 0.36; 'possible': 0.36; 'so,': 0.37; 'implement': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'reserved': 0.61; "you're": 0.61; 'received:74.208': 0.68; 'biggie': 0.84; 'carlos': 0.91; 'subject: #': 0.96 Date: Tue, 28 May 2013 15:57:49 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Python #ifdef References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:efboiy7KV4igMtAbAO1AmnvZx+Vs4Q12NbAhBU9eISX RO/y/j6AOqI2v0+eD9Q6ztsQHvX6TEIOHpSkfWmW2BspeYXl5m HC5R2klErqrGcfs/dJrJvNfqnsUziL3YS8/zeI01/9bjnulg7c 2pCBtep8n9ZID83f9ji37IREtMFxhh5mfTk7AaGGof5DJrWN3t QtXQ4yAtrhEIoQxfpCDYN2i41WsWtvM2rbr0iubX/n0fZjjyg8 WqdzuUn3G+ZUBngm8/KmcQ7PpVlPqXK7gJ1CJQCOA18jmJJVne n0keS8GiTmQmutoFL45b9ZxtZMCy/LVnf/eIep12rpRcErpNfl JrciE+gQnHoTTCV0EKjM= 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369771083 news.xs4all.nl 15997 [2001:888:2000:d::a6]:51609 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46331 On 05/28/2013 03:46 PM, Carlos Nepomuceno wrote: > Are there Python 'preprocessor directives'? Python doesn't define a preprocessor, and CPYthon doesn't implement one. Nothing to stop you from doing so, however. > > I'd like to have something like '#ifdef' to mix code from Python 2 and 3 in a single file. > > Is that possible? How? > It's quite possible that you don't need a preprocessor do what you want, since Python does much less compile-time checking than C. Also, it's possible to store function objects and module objects in variables, and thus to hide many things from the body of the code. One biggie is print, since that's a reserved word (and a statement) in Python 2.x. But if you're using 2.7 you can use from __future__ import print, or something like that, and just use 3.x function semantics. -- DaveA