keeping tabs on 2.x

A forum for general discussion of the Python programming language.

keeping tabs on 2.x

Postby metulburr » Wed Jun 26, 2013 11:49 pm

I mostly use 3.x, and use 2.x to run othjers programs. But I actually just noticed this tinkering in the interpreter of 2.x:
So print as a function, range() (i think there was something else) all work without using __future__, I could of sworn that maybe a year or two ago range() would break 2.x. Or maybe you dont need __future__ for 2.7.4 anymore?
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1469
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: keeping tabs on 2.x

Postby Yoriz » Thu Jun 27, 2013 12:32 am

I'm the other way around and mostly use 2.x and have 3.x for running others code
print works with open and close brackets only
Code: Select all
print('this')

This gives SyntaxError: invalid syntax
Code: Select all
print('this', end=',')

range has always worked but range returns a list, xrange returns a generator which is the same behavour as 3.x range.
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 831
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: keeping tabs on 2.x

Postby micseydel » Thu Jun 27, 2013 2:17 am

metulburr wrote:without using __future__, I could of sworn that maybe a year or two ago range() would break 2.x.

Could you elaborate on what you mean by this?
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1354
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: keeping tabs on 2.x

Postby metulburr » Thu Jun 27, 2013 2:18 am

Code: Select all
from __future__ import print_function
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1469
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: keeping tabs on 2.x

Postby micseydel » Thu Jun 27, 2013 2:21 am

What does that have to do with range()? What do you mean it "breaks"?
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1354
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: keeping tabs on 2.x

Postby metulburr » Thu Jun 27, 2013 12:23 pm

well no longer currently in 2.7.4, maybe i was thinking 2.7.1 or even 2.6
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1469
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: keeping tabs on 2.x

Postby micseydel » Thu Jun 27, 2013 12:31 pm

I still have absolutely no idea what you're trying to say or talk about.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1354
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: keeping tabs on 2.x

Postby Mekire » Thu Jun 27, 2013 2:06 pm

print doesn't work as a function in 2.x without the from future import. If you try to put it in a dictionary or assign it to a different name like you could a normal function you will see.

range has always (to my knowledge) worked in 2.x it just returns a list rather than a generator. xrange returns the generator in 2.x. Come 3.x range was removed and xrange was renamed to range (similar to how input was removed in 3.x and raw_input was renamed input). This means that most code that uses range would still run in 2.x it just wouldn't perform as well.

Big things that always get me are the difference between default integer division (2.x) and default true division (3.x). To combat this, I always try to use "//" when I want integer division, and I make damn sure one of the values is a float if I want true.

Super is annoyingly incompatible. If you do it the nice way that 3.x allows then it won't work in 2.x; and if you do it the way 2.x allows... well... you aren't really saving any time. I just avoid its use.

You can no longer put parenthetic arguments in function definitions in 3.x either (not that there should ever be a need to but I have hit it in others' code).
Code: Select all
def func(a,(b,c)):
    print a,b,c
The above would work in 2.x but not 3.x.

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: keeping tabs on 2.x

Postby ochichinyezaboombwa » Fri Jun 28, 2013 3:40 am

And the conclusion is?..
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm

Re: keeping tabs on 2.x

Postby Mekire » Fri Jun 28, 2013 4:12 am

My personal conclusion has been that if you don't maintain compatibility with both versions, then someone will eventually complain. As such I make everything as compatible as possible, which of course makes the fact that their are two versions of python an annoyance not a blessing. I would gladly use nothing but py3 if this were an option; but as it isn't, I use py2 and if at all possible, code in such a way as not to break compatibility.

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 2 guests