FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Python different version





roneetshaw
Why there are so many code syntax change in python 2.7 and Python 3.5 ?
SonLight
The developers of Python recognized they had made some design choices that would limit its use in the future, unless they somehow came out with changes which were not backward compatible. They have provided tools that help move old code forward, but it is difficult to write code that works on both versions. The most important difference is that strings are in Unicode in Python 3 and there is a byte type which can hold arbitrary binary data, and you must specify the character encoding when converting strings to or from an external format.

If you are using 2.7 and happy with it, you may want to keep using it until you have good reason to change. If you want to write Python 3 compatible code, I suggest writing it so it is as easy as possible to backport it to 2.7 if needed. I use the following statements at the beginning of most of my source files.

Code:
from __future__ import print_function, division

import sys

pythonversion = sys.version_info[0]  # should be two or three
if pythonversion < 3:
    input = raw_input  # insure that non-eval version of input always used


The imports from __future__ cause 2.7 to work like 3, and have no effect when running in version 3. Now I can write:

print(whatever), and it gives the same output in either version; and division is exact (with possible fractional result) in either. The // to divide and return an integer of course always works the same in either.

I'm not happy with the input vs raw_input feature, but I don't want to take a chance of having an eval done unexpectedly when running under 2.7.
Related topics
Creating a new Operating System
Windows Vista Official Thread
how do you get linux
Big Brother 6
Ragnarok Online 2 Beta Test
Air Marshal Kills Passenger at Miami Airport
photoshop prob
PSP
FireFox big issues!!!!
need help with blog??
May i Install EyeOs in my hosting?
Freeze
Maya help
backing up a db in phpbb
Mod_python not working on server 4
Reply to topic    Frihost Forum Index -> General -> General Chat

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.