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


Groups > comp.lang.python > #46331

Re: Python #ifdef

Date 2013-05-28 15:57 -0400
From Dave Angel <davea@davea.name>
Subject Re: Python #ifdef
References <BLU176-W12FAFEA3C7AFD687855E04D7970@phx.gbl>
Newsgroups comp.lang.python
Message-ID <mailman.2319.1369771083.3114.python-list@python.org> (permalink)

Show all headers | View raw


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

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


Thread

Re: Python #ifdef Dave Angel <davea@davea.name> - 2013-05-28 15:57 -0400

csiph-web