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?
we will be moving to python-forum.io on October 1 2016
more details here
User avatar
metulburr
 
Posts: 2228
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.
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Yoriz
 
Posts: 1672
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?
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 2995
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
we will be moving to python-forum.io on October 1 2016
more details here
User avatar
metulburr
 
Posts: 2228
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"?
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 2995
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
we will be moving to python-forum.io on October 1 2016
more details here
User avatar
metulburr
 
Posts: 2228
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.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 2995
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
New Users, Read This
  • Use code tags when posting code.
  • Include any errors with your post (in code tags).
  • Describe your problem; not your chosen solution.
  • Make examples the minimum length to demonstrate your issue.
User avatar
Mekire
 
Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

Re: keeping tabs on 2.x

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

And the conclusion is?..
ochichinyezaboombwa
 
Posts: 203
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
New Users, Read This
  • Use code tags when posting code.
  • Include any errors with your post (in code tags).
  • Describe your problem; not your chosen solution.
  • Make examples the minimum length to demonstrate your issue.
User avatar
Mekire
 
Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 3 guests