Re: Python #ifdef

2013-06-12 Thread Chris Angelico
On Tue, Jun 4, 2013 at 8:18 AM, Carlos Nepomuceno wrote: > >> Date: Mon, 3 Jun 2013 12:05:49 +1000 >> Subject: Re: Python #ifdef >> From: ros...@gmail.com >> To: python-list@python.org > [...] >> Ah. I actually wasn&

RE: Python #ifdef

2013-06-12 Thread Carlos Nepomuceno
> Date: Mon, 3 Jun 2013 12:05:49 +1000 > Subject: Re: Python #ifdef > From: ros...@gmail.com > To: python-list@python.org [...] > Ah. I actually wasn't aware of m4's use with sendmail. I first met it > as the aforementioned

Re: Python #ifdef

2013-06-02 Thread Chris Angelico
On Mon, Jun 3, 2013 at 9:57 AM, Erik Max Francis wrote: > On 05/29/2013 08:05 AM, Chris Angelico wrote: >> >> It's not a bad tool. I used it as a sort of PHP preprocessor, because >> requirements at work had me wanting to have a source file defining a >> PHP class and having an autogenerated secti

Re: Python #ifdef

2013-06-02 Thread Skip Montanaro
> The terror that most people feel when hearing "m4" is because m4 was associated with sendmail, not because m4 was inherently awful. In fact, m4 made sendmail configs easier to maintain. Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: Python #ifdef

2013-06-02 Thread Roy Smith
In article , Erik Max Francis wrote: > On 05/29/2013 08:05 AM, Chris Angelico wrote: > > It's not a bad tool. I used it as a sort of PHP preprocessor, because > > requirements at work had me wanting to have a source file defining a > > PHP class and having an autogenerated section in the middle

Re: Python #ifdef

2013-06-02 Thread Erik Max Francis
On 05/29/2013 08:05 AM, Chris Angelico wrote: It's not a bad tool. I used it as a sort of PHP preprocessor, because requirements at work had me wanting to have a source file defining a PHP class and having an autogenerated section in the middle of that class. PHP's 'include' directive doesn't wor

Re: Python #ifdef

2013-05-29 Thread Grant Edwards
On 2013-05-29, Chris Angelico wrote: > On Thu, May 30, 2013 at 12:55 AM, Grant Edwards > wrote: >> On 2013-05-29, Dan Stromberg wrote: >> >>> And in case you still want a preprocessor for Python (you likely don't need >>> one this time), here's an example of doing this using the venerable m4: >

Re: Python #ifdef

2013-05-29 Thread Chris Angelico
On Thu, May 30, 2013 at 12:55 AM, Grant Edwards wrote: > On 2013-05-29, Dan Stromberg wrote: > >> And in case you still want a preprocessor for Python (you likely don't need >> one this time), here's an example of doing this using the venerable m4: >> https://pypi.python.org/pypi/red-black-tree-m

Re: Python #ifdef

2013-05-29 Thread Grant Edwards
On 2013-05-29, Dan Stromberg wrote: > And in case you still want a preprocessor for Python (you likely don't need > one this time), here's an example of doing this using the venerable m4: > https://pypi.python.org/pypi/red-black-tree-mod . Note the many comments > added to keep line numbers cons

Re: Python #ifdef

2013-05-29 Thread Grant Edwards
On 2013-05-28, Carlos Nepomuceno wrote: > How do you have "invalid@invalid.invalid" instead of your email address? I have this in my .slrnrc: set hostname "invalid.invalid" set username "grant" set realname "Grant Edwards" I'm not sure why it doesn't show up as grant@invalid.invalid -- I th

Re: Python #ifdef

2013-05-28 Thread Dan Stromberg
Here're slides from a presentation about writing code that runs on 2.x and 3.x: http://stromberg.dnsalias.org/~dstromberg/Intro-to-Python/ And in case you still want a preprocessor for Python (you likely don't need one this time), here's an example of doing this using the venerable m4: https://pyp

Supporting both 2.x and 3.x in one code base [was Re: Python #ifdef]

2013-05-28 Thread Steven D'Aprano
On Tue, 28 May 2013 18:25:59 -0400, Joel Goldstick wrote: > 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. Not so much a bear as a tiny little kitten. > I wouldn't do it > unless there was some imposing reaso

Re: Python #ifdef

2013-05-28 Thread Terry Jan Reedy
On 5/28/2013 6:25 PM, Joel Goldstick wrote: On Tue, May 28, 2013 at 6:18 PM, Mark Lawrence mailto:breamore...@yahoo.co.uk>> wrote: On 28/05/2013 20:46, Carlos Nepomuceno wrote: I'd like to have something like '#ifdef' to mix code from Python 2 and 3 in a single file.

Re: Python #ifdef

2013-05-28 Thread 88888 Dihedral
Carlos Nepomuceno於 2013年5月29日星期三UTC+8上午3時46分37秒寫道: > 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? Use execfile(filename) at the beginning to get what you want. The .pyc ver

RE: Python #ifdef

2013-05-28 Thread Fábio Santos
On 28 May 2013 21:53, "Carlos Nepomuceno" wrote: > > > > Date: Tue, 28 May 2013 21:34:36 +0100 > > Subject: RE: Python #ifdef > > From: fabiosantos...@gmail.com > > To: carlosnepomuc...@outlook.com > > CC: python-li

RE: Python #ifdef

2013-05-28 Thread Carlos Nepomuceno
> Date: Tue, 28 May 2013 18:25:59 -0400 > Subject: Re: Python #ifdef > From: joel.goldst...@gmail.com > To: breamore...@yahoo.co.uk > CC: python-list@python.org [...] > > my original response was from cell phone. I just answered that yo

Re: Python #ifdef

2013-05-28 Thread Joel Goldstick
On Tue, May 28, 2013 at 6:18 PM, Mark Lawrence 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://py

Re: Python #ifdef

2013-05-28 Thread Mark Lawrence
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 -- If you're

RE: Python #ifdef

2013-05-28 Thread Carlos Nepomuceno
> From: invalid@invalid.invalid > Subject: Re: Python #ifdef > Date: Tue, 28 May 2013 20:42:34 + > To: python-list@python.org [...] > Here's the important lesson from this thread: > > Instead of asking "how do I write X in

RE: Python #ifdef

2013-05-28 Thread Carlos Nepomuceno
> Date: Tue, 28 May 2013 21:34:36 +0100 > Subject: RE: Python #ifdef > From: fabiosantos...@gmail.com > To: carlosnepomuc...@outlook.com > CC: python-list@python.org > > > On 28 May 2013 21:26, "Carlos Nepomuceno" >

Re: Python #ifdef

2013-05-28 Thread Grant Edwards
On 2013-05-28, Carlos Nepomuceno wrote: > [...] >> You're trying to make this a lot harder than it really is: >> >> if sys.version_info[0] == 3: >> def original(n): >> m = 0 >> for b in n.to_bytes(6, 'big'): >> m = 256*m + b >> return m >> else: >> def original(n): >> > > Haha! That's it!!! > >

RE: Python #ifdef

2013-05-28 Thread Fábio Santos
On 28 May 2013 21:26, "Carlos Nepomuceno" wrote: > Haha! That's it!!! > > Just realized how funny this can be: ;) > > ### never to be opened ### > def pandoras_box(v): > return v/0.0 > > if customer_didnt_pay(): > pandoras_box() > > #lol 1/0 is, after print, my most common debug statement

RE: Python #ifdef

2013-05-28 Thread Carlos Nepomuceno
> From: invalid@invalid.invalid > Subject: Re: Python #ifdef [...] > You're trying to make this a lot harder than it really is: > > if sys.version_info[0] == 3: > def original(n): > m = 0 > for b in n.to_bytes(6, 'big&#x

RE: Python #ifdef

2013-05-28 Thread Benjamin Kaplan
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

Re: Python #ifdef

2013-05-28 Thread Grant Edwards
On 2013-05-28, 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 >

RE: Python #ifdef

2013-05-28 Thread Carlos Nepomuceno
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)

Re: Python #ifdef

2013-05-28 Thread Neil Cerutti
On 2013-05-28, Joel Goldstick wrote: > > No Yes. More below. > On May 28, 2013 3:48 PM, "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? Y

Re: Python #ifdef

2013-05-28 Thread Dave Angel
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 si

Re: Python #ifdef

2013-05-28 Thread Joel Goldstick
No On May 28, 2013 3:48 PM, "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? > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://