Re: Python 2.x and 3.x usage survey

Discussion in 'Python' started by Steve Hayes, Jan 1, 2014.

  1. Steve Hayes

    Steve Hayes Guest

    On Mon, 30 Dec 2013 13:56:30 -0800, Dan Stromberg <> wrote:

    >I keep hearing naysayers, nay saying about Python 3.x.
    >
    >Here's a 9 question, multiple choice survey I put together about
    >Python 2.x use vs Python 3.x use.
    >
    >I'd be very pleased if you could take 5 or 10 minutes to fill it out.


    I had a look at it, but I've got about as far as "Hello World" in both.

    I borrowed a book called "Learning Python" by Lutz and Asher, which is geared
    for 2.2/2.3.

    But the version I have in Windows is 3.2, and it seems that even "Hello World"
    presents and insurmountable problem.

    Eventually I discovered that one of the differences bytween 2.x and 3.x is
    that the former has "print" and the latter has "print()" but weven using that
    it tells me it cant find the PRN device or something.

    I've got 2.x on Linux, so I booted into that and it seemed to work there, but
    it seems that the differences between the versions are not trivial.

    So perhaps I should just try to install 2.x in Windows, and learn that.


    --
    Steve Hayes from Tshwane, South Africa
    Web: http://www.khanya.org.za/stevesig.htm
    Blog: http://khanya.wordpress.com
    E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk
    Steve Hayes, Jan 1, 2014
    #1
    1. Advertising

  2. On Wed, Jan 1, 2014 at 9:41 PM, Steve Hayes <> wrote:
    > I borrowed a book called "Learning Python" by Lutz and Asher, which is geared
    > for 2.2/2.3.


    That's really REALLY old. Even Red Hat isn't still supporting 2.2. You
    can quite easily get started on 3.2 on Windows - though I would
    recommend grabbing 3.3 and using that - just start with this tutorial:

    http://docs.python.org/3/tutorial/

    I don't know exactly what will be different in 2.2, but there's no
    point learning a version that old. If nothing else, you'll miss out on
    a lot of neat features.

    ChrisA
    Chris Angelico, Jan 1, 2014
    #2
    1. Advertising

  3. Steve Hayes wrote:

    > I borrowed a book called "Learning Python" by Lutz and Asher, which is
    > geared for 2.2/2.3.
    >
    > But the version I have in Windows is 3.2, and it seems that even "Hello
    > World" presents and insurmountable problem.


    It certainly is not *insurmountable*. Not unless you consider typing
    brackets ( ) to be an inhumanly difficult task, in which case you might as
    well give up on being a programmer and take up something easier like brain
    surgery.

    # Python 2 version
    print "Hello World!"

    # Python 3 version
    print("Hello World!")



    > Eventually I discovered that one of the differences bytween 2.x and 3.x is
    > that the former has "print" and the latter has "print()" but weven using
    > that it tells me it cant find the PRN device or something.


    Possibly you're trying to run print("Hello World") at the DOS command prompt
    rather than using Python. I'm not sure exactly what you're doing, but I do
    know that you shouldn't get any errors about the PRN device from Python.
    That sounds like it is a Windows error.


    > I've got 2.x on Linux, so I booted into that and it seemed to work there,
    > but it seems that the differences between the versions are not trivial.


    For the most part, they are trivial. With only a few exceptions, everything
    in Python 2 can be easily, even mechanically, translated to Python 3.

    Python 3 includes a lot of new features that a Python 2.3 book won't even
    mention. But if course, since the book doesn't mention them, you won't need
    to deal with them. It also includes a few changes from statements to
    functions, like print and exec (but as a beginner, you shouldn't be using
    exec). A few modules have been renamed. In my personal opinion, the most
    annoying change from Python 2 to 3 is renaming modules, because I can never
    remember the new name.

    None of these are *difficult* changes. As a beginner, of course, you cannot
    be expected to automatically know how to deal with a problem like this one:

    py> from StringIO import StringIO
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ImportError: No module named 'StringIO'


    But let me give you a secret known only to a few: to solve this problem is
    not hard. Just google for "StringIO renamed Python 3". which will take you
    to the "What's New in Python 3" document, which reveals that the StringIO
    module is renamed to io.StringIO, and so you should use this instead:

    from io import StringIO


    https://duckduckgo.com/?q=StringIO renamed Python 3


    If googling fails, feel free to ask here!


    --
    Steven
    Steven D'Aprano, Jan 1, 2014
    #3
  4. Steve Hayes

    Steve Hayes Guest

    On Wed, 01 Jan 2014 22:37:45 +1100, Steven D'Aprano
    <> wrote:

    >Steve Hayes wrote:
    >
    >> I borrowed a book called "Learning Python" by Lutz and Asher, which is
    >> geared for 2.2/2.3.
    >>
    >> But the version I have in Windows is 3.2, and it seems that even "Hello
    >> World" presents and insurmountable problem.

    >
    >It certainly is not *insurmountable*. Not unless you consider typing
    >brackets ( ) to be an inhumanly difficult task, in which case you might as
    >well give up on being a programmer and take up something easier like brain
    >surgery.
    >
    ># Python 2 version
    >print "Hello World!"
    >
    ># Python 3 version
    >print("Hello World!")


    I was thinking or of this:

    >>> python g:\work\module1.py

    File "<stdin>", line 1
    python g:\work\module1.py
    ^

    Which gave a different error the previous time I did it.

    But, hey, it worked from the DOS prompt

    C:\Python32>python g:\work\module1.py
    Hello Module World

    But hey, don't mind me.

    The biggest problem I have is that when something doesn't work, I don't know
    if I have done something stupid, or if it's just an incompatibility of the
    different versions.



    --
    Steve Hayes from Tshwane, South Africa
    Web: http://www.khanya.org.za/stevesig.htm
    Blog: http://khanya.wordpress.com
    E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk
    Steve Hayes, Jan 1, 2014
    #4
  5. On Wed, Jan 1, 2014 at 11:38 PM, Steve Hayes <> wrote:
    > I was thinking or of this:
    >
    >>>> python g:\work\module1.py

    > File "<stdin>", line 1
    > python g:\work\module1.py
    > ^
    >
    > Which gave a different error the previous time I did it.
    >
    > But, hey, it worked from the DOS prompt
    >
    > C:\Python32>python g:\work\module1.py
    > Hello Module World


    That's how you invoke a script. Python isn't fundamentally a shell
    scripting language (like bash, REXX, batch, etc), so there's a
    distinct difference between Python commands (which go into .py files
    or are executed at the ">>>" prompt) and shell commands (including
    "python", which invokes the Python interpreter).

    > The biggest problem I have is that when something doesn't work, I don't know
    > if I have done something stupid, or if it's just an incompatibility of the
    > different versions.


    Easiest way to eliminate the confusion is to match your tutorial and
    your interpreter. That's why I recommend going with the python.org
    tutorial; you can drop down the little box in the top left and choose
    the exact version of Python that you're running. It WILL match.

    ChrisA
    Chris Angelico, Jan 1, 2014
    #5
  6. On 01/01/2014 12:38, Steve Hayes wrote:
    > On Wed, 01 Jan 2014 22:37:45 +1100, Steven D'Aprano
    > <> wrote:
    >
    >> Steve Hayes wrote:
    >>
    >>> I borrowed a book called "Learning Python" by Lutz and Asher, which is
    >>> geared for 2.2/2.3.
    >>>
    >>> But the version I have in Windows is 3.2, and it seems that even "Hello
    >>> World" presents and insurmountable problem.

    >>
    >> It certainly is not *insurmountable*. Not unless you consider typing
    >> brackets ( ) to be an inhumanly difficult task, in which case you might as
    >> well give up on being a programmer and take up something easier like brain
    >> surgery.
    >>
    >> # Python 2 version
    >> print "Hello World!"
    >>
    >> # Python 3 version
    >> print("Hello World!")

    >
    > I was thinking or of this:
    >
    >>>> python g:\work\module1.py

    > File "<stdin>", line 1
    > python g:\work\module1.py
    > ^
    >
    > Which gave a different error the previous time I did it.
    >
    > But, hey, it worked from the DOS prompt
    >
    > C:\Python32>python g:\work\module1.py
    > Hello Module World
    >
    > But hey, don't mind me.
    >
    > The biggest problem I have is that when something doesn't work, I don't know
    > if I have done something stupid, or if it's just an incompatibility of the
    > different versions.
    >


    Almost inevitably if you search for the last line of the error that you
    get you'll find more than enough hits to point you in the right
    direction. Failing that ask here as we don't bite. There's also the
    tutor mailing list https://mail.python.org/mailman/listinfo/tutor

    --
    My fellow Pythonistas, ask not what our language can do for you, ask
    what you can do for our language.

    Mark Lawrence
    Mark Lawrence, Jan 1, 2014
    #6
  7. Steve Hayes

    David Guest

    On 1 January 2014 23:38, Steve Hayes <> wrote:
    >
    > I was thinking or of this:
    >
    >>>> python g:\work\module1.py

    > File "<stdin>", line 1
    > python g:\work\module1.py
    > ^
    >
    > Which gave a different error the previous time I did it.
    >
    > But, hey, it worked from the DOS prompt
    >
    > C:\Python32>python g:\work\module1.py
    > Hello Module World


    Your windows command shell prompt looks like this: "C:\Python32>"
    It indicates that windows shell is waiting for you to type something.
    It expects the first word you type to be an executable command. If you
    do this:
    C:\Python32>python g:\work\module1.py
    it tells the shell to run the python interpreter and feed it all the
    python statments contained in the file g:\work\module1.py

    If you do this:
    C:\Python32>python
    it tells the shell to run the python interpreter interactively, and
    wait for you to directly type python statements. When the python
    intepreter is ready for you to type a python statement, it gives you a
    ">>>" prompt. It expects you to type a valid python language
    statement.

    The reason this gave an error:
    >>> python g:\work\module1.py


    is because you are using the python interpreter as shown by ">>>", but
    you typed a windows shell command, not a python statement.
    David, Jan 1, 2014
    #7
  8. Steve Hayes

    Dave Angel Guest

    On Wed, 01 Jan 2014 14:38:59 +0200, Steve Hayes
    <> wrote:
    > >>> python g:\work\module1.py

    > File "<stdin>", line 1
    > python g:\work\module1.py
    > ^



    > Which gave a different error the previous time I did it.



    > But, hey, it worked from the DOS prompt



    > C:\Python32>python g:\work\module1.py
    > Hello Module World


    You need to understand that you are using two VERY different
    languages, one at the DOS prompt, the other at the python prompt
    and in .py files. You cannot use shell syntax at the python prompt,
    any more than you can do the reverse.

    --
    DaveA
    Dave Angel, Jan 1, 2014
    #8
  9. On Wed, 01 Jan 2014 12:41:44 +0200, Steve Hayes <>
    declaimed the following:

    >
    >But the version I have in Windows is 3.2, and it seems that even "Hello World"
    >presents and insurmountable problem.
    >
    >Eventually I discovered that one of the differences bytween 2.x and 3.x is
    >that the former has "print" and the latter has "print()" but weven using that
    >it tells me it cant find the PRN device or something.
    >
    >I've got 2.x on Linux, so I booted into that and it seemed to work there, but
    >it seems that the differences between the versions are not trivial.
    >
    >So perhaps I should just try to install 2.x in Windows, and learn that.


    Off hand I suspect you didn't follow the same process on Linux as you
    did on Windows.

    But as you didn't cut&paste the exact code and invocation/error message
    we have to guess.

    -=-=-=-=-
    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    C:\Users\Wulfraed\Documents>print("hello lunar")
    Unable to initialize device PRN

    C:\Users\Wulfraed\Documents>print "hello moon"
    Unable to initialize device PRN

    C:\Users\Wulfraed\Documents>python
    ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
    Python 2.7.2 (default, Jun 24 2011, 12:22:14) [MSC v.1500 64 bit (AMD64)]
    on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> print("hello lunar")

    hello lunar
    >>> print "hello moon"

    hello moon
    >>> ^Z


    C:\Users\Wulfraed\Documents>


    -=-=-=-=-
    --
    Wulfraed Dennis Lee Bieber AF6VN
    HTTP://wlfraed.home.netcom.com/
    Dennis Lee Bieber, Jan 1, 2014
    #9
  10. Steve Hayes

    Steve Hayes Guest

    On Thu, 2 Jan 2014 01:07:54 +1100, David <> wrote:

    >On 1 January 2014 23:38, Steve Hayes <> wrote:
    >>
    >> I was thinking or of this:
    >>
    >>>>> python g:\work\module1.py

    >> File "<stdin>", line 1
    >> python g:\work\module1.py
    >> ^
    >>
    >> Which gave a different error the previous time I did it.
    >>
    >> But, hey, it worked from the DOS prompt
    >>
    >> C:\Python32>python g:\work\module1.py
    >> Hello Module World

    >
    >Your windows command shell prompt looks like this: "C:\Python32>"
    >It indicates that windows shell is waiting for you to type something.
    >It expects the first word you type to be an executable command. If you
    >do this:
    > C:\Python32>python g:\work\module1.py
    >it tells the shell to run the python interpreter and feed it all the
    >python statments contained in the file g:\work\module1.py
    >
    >If you do this:
    > C:\Python32>python
    >it tells the shell to run the python interpreter interactively, and
    >wait for you to directly type python statements. When the python
    >intepreter is ready for you to type a python statement, it gives you a
    >">>>" prompt. It expects you to type a valid python language
    >statement.
    >
    >The reason this gave an error:
    >>>> python g:\work\module1.py

    >
    >is because you are using the python interpreter as shown by ">>>", but
    >you typed a windows shell command, not a python statement.


    Thank you. Back to the book!


    --
    Steve Hayes from Tshwane, South Africa
    Web: http://www.khanya.org.za/stevesig.htm
    Blog: http://khanya.wordpress.com
    E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk
    Steve Hayes, Jan 1, 2014
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Berg

    Re: Python 2.x and 3.x usage survey

    Andrew Berg, Dec 30, 2013, in forum: Python
    Replies:
    0
    Views:
    50
    Andrew Berg
    Dec 30, 2013
  2. Chris Angelico

    Re: Python 2.x and 3.x usage survey

    Chris Angelico, Dec 30, 2013, in forum: Python
    Replies:
    0
    Views:
    51
    Chris Angelico
    Dec 30, 2013
  3. Dennis Lee Bieber

    Re: Python 2.x and 3.x usage survey

    Dennis Lee Bieber, Dec 31, 2013, in forum: Python
    Replies:
    0
    Views:
    52
    Dennis Lee Bieber
    Dec 31, 2013
  4. Cameron Simpson

    Re: Python 2.x and 3.x usage survey

    Cameron Simpson, Dec 31, 2013, in forum: Python
    Replies:
    0
    Views:
    61
    Cameron Simpson
    Dec 31, 2013
  5. Mark Lawrence

    Re: Python 2.x and 3.x usage survey

    Mark Lawrence, Dec 31, 2013, in forum: Python
    Replies:
    4
    Views:
    64
    emile
    Jan 3, 2014
Loading...

Share This Page