[Tutor] breeds of Python .....

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

[Tutor] breeds of Python .....

Barry Drake-2
After following the reading suggestions, I soon found myself looking at
quite a few code examples that would only run under a particular version
of python.  Finally, I converted the example that I was working on to
run under Python3.  I just wondered if you guys would advise a newbie
like me to concentrate on Python3 or stay with Python2 and get into bad
habits when it comes to change eventually?  Apart from the print and
input functions, I haven't so far got a lot to re-learn.

Kind regards,        Barry.

--
 From Barry Drake - a member of the Ubuntu advertising team.

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: [Tutor] breeds of Python .....

modulok-2
After following the reading suggestions, I soon found myself looking
at quite a few code examples that would only run under a particular
version of python.  Finally, I converted the example that I was
working on to run under Python3.  I just wondered if you guys would
advise a newbie like me to concentrate on Python3 or stay with Python2
and get into bad habits when it comes to change eventually?  Apart
from the print and input functions, I haven't so far got a lot to
re-learn.

Kind regards,        Barry.


Barry,

If you're just starting out, go with 3.x. If you have a need for some third
party modules that aren't yet available for 3.x, you'll have to stick with 2.x.
Most beginner tutorials will work without changes, except for the print
statement is now a function, e.g:

    print "foo"

Is now:

    print("foo")

There isn't a whole lot of difference in syntax to learn. Some modules have
been renamed, some module functions re-worked, etc. Probably the biggest change
is the move to all unicode strings. One thing you can do if you're running 2.x
but want to get into the 3.x swing of things is turn on 3.x warnings. It will
tell you if you did something the 2to3 tool can't automatically fix:

    python2.6 -3

If you want, you can actually use the 3.x style print function and true
division when using 2.x by putting this at the top of your code::

    from __future__ import print_function
    from __future__ import division

Now in 2.x, just like 3.x this will raise an exception:

    print "foo"     #<-- Now fails in 2.x
    print("foo")    #<-- Works.

-Modulok-
_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: [Tutor] breeds of Python .....

S.Irfan Rizvi
please remove me from here

















On Sat, Mar 31, 2012 at 4:28 PM, Modulok <[hidden email]> wrote:

> After following the reading suggestions, I soon found myself looking
> at quite a few code examples that would only run under a particular
> version of python.  Finally, I converted the example that I was
> working on to run under Python3.  I just wondered if you guys would
> advise a newbie like me to concentrate on Python3 or stay with Python2
> and get into bad habits when it comes to change eventually?  Apart
> from the print and input functions, I haven't so far got a lot to
> re-learn.
>
> Kind regards,        Barry.
>
>
> Barry,
>
> If you're just starting out, go with 3.x. If you have a need for some third
> party modules that aren't yet available for 3.x, you'll have to stick with 2.x.
> Most beginner tutorials will work without changes, except for the print
> statement is now a function, e.g:
>
>    print "foo"
>
> Is now:
>
>    print("foo")
>
> There isn't a whole lot of difference in syntax to learn. Some modules have
> been renamed, some module functions re-worked, etc. Probably the biggest change
> is the move to all unicode strings. One thing you can do if you're running 2.x
> but want to get into the 3.x swing of things is turn on 3.x warnings. It will
> tell you if you did something the 2to3 tool can't automatically fix:
>
>    python2.6 -3
>
> If you want, you can actually use the 3.x style print function and true
> division when using 2.x by putting this at the top of your code::
>
>    from __future__ import print_function
>    from __future__ import division
>
> Now in 2.x, just like 3.x this will raise an exception:
>
>    print "foo"     #<-- Now fails in 2.x
>    print("foo")    #<-- Works.
>
> -Modulok-
> _______________________________________________
> Tutor maillist  -  [hidden email]
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor



--
       Regards
     ~ S. Irfan Rizvi
 ADR-TS
_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: [Tutor] breeds of Python .....

S.Irfan Rizvi
please remove me from here
_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: [Tutor] breeds of Python .....

Brett Ritter
In reply to this post by Barry Drake-2
On Sat, Mar 31, 2012 at 5:37 PM, Barry Drake <[hidden email]> wrote:
> concentrate on Python3 or stay with Python2 and get into bad habits when it
> comes to change eventually?  Apart from the print and input functions, I
> haven't so far got a lot to re-learn.

My recommendation is to go with Python2 - most major projects haven't
made the switch and I'd expect another year or two before they do so.
Many tutorials and examples are Python 2-based and there are not that
many differences to unlearn in terms of habits.

--
Brett Ritter / SwiftOne
[hidden email]
_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: [Tutor] breeds of Python .....

Barry Drake-2
On 01/04/12 06:19, Brett Ritter wrote:
> My recommendation is to go with Python2 - most major projects haven't
> made the switch and I'd expect another year or two before they do so.
> Many tutorials and examples are Python 2-based and there are not that
> many differences to unlearn in terms of habits.

Thanks Brett and those who replied.  As my only reason for getting into
Python is to be able to show the kids at the local school a bit about
programming, and as I've no investment in existing code at all, I'm
going to go with Python3.  The tutorials and examples I have are as
plentiful in Python3 as in Python2, and the ones I might want from the
Python2 tutorial will be easy to convert and will help the learning
process.

The main reason I asked the opinion of this list was in case there was a
vast opinion gap like there is in Ubuntu between Unity lovers and Unity
haters.  I guess Unity is a bit like Marmite.  I get the view that
Python3 is just a natural progression.  I never experienced this with c
as the standard library base on Kernighan and Ritchie never seemed to
change its syntax from the word go.

Kind regards,        Barry.

--
 From Barry Drake - a member of the Ubuntu advertising team.

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: [Tutor] breeds of Python .....

Barry Drake-2
In reply to this post by Barry Drake-2

On 01/04/12 12:03, Leam Hall wrote:
>  For that path I'd agree that Python 3 is the way to go. I believe
>  PyGame is Python 3 ready so you've got an automatic hook for the kids.
>  Heck, probably many of their parents as well!
>  Check out the book "More Python programming for the absolute beginner"
>  as it teaches Python and PyGame at the same time.

I've played around with PyGame on Python2 - hadn't realised it was ready
for Python3 yet.  It's just the kind of thing that would have sparked my
son off when he was a kid.  He wrote hundreds of lines in the rather
dumb Basic that the Speccy used in the olden days, and guess what - when
he went to uni, his degree was in computer science!  I really hated
Basic, and programmed in Z80 assembler until I met with c and learned
how much fun programming could really be.  Python is even more fun.

I was a bit taken aback a few years later when my son left his job as
sys-admin for a big firm.  He said that the work was a job for a
twenty-year old whiz-kid.  He was more interested in how business
works.  He now charges an absolute fortune as a freelance consultant.

Kind regards,        Barry

--
 From Barry Drake - a member of the Ubuntu advertising team.


_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: [Tutor] breeds of Python .....

Alan Gauld
In reply to this post by Barry Drake-2
On 01/04/12 11:43, Barry Drake wrote:
> On 01/04/12 06:19, Brett Ritter wrote:

> is just a natural progression. I never experienced this with c as the
> standard library base on Kernighan and Ritchie never seemed to change
> its syntax from the word go.

Actually the standardization of C sparked huge debates in the
early 90's. There were lots of minor changes and one big style change
that really polarised opinions. In traditional C you defined a functions
parameters like

int foo()
int a;
float b;
{  /* body here */  }


in ANSI that changed to:

inf foo(int a, float b)
{ // body here }


The changes from Python 2 to Python 3 have been a model of harmony in
comparison, and they are the biggest changes in Python's 20 year history.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: [Tutor] breeds of Python .....

Barry Drake-2
In reply to this post by Barry Drake-2
On 01/04/12 12:03, Leam Hall wrote:
> I believe PyGame is Python 3 ready so you've got an automatic hook for
> the kids. Heck, probably many of their parents as well!

PyGame is available for Python3 but not pre-built from the Ubuntu or
Debian repos as far as I can see.  I got the source from the PyGame site
and built it.  Note that the required c headers to build it are not in
the standard install of Python3, so I had to get the matching source
package and manually put the headers into the appropriate place.  After
that, it seems to build and work OK, and the PyGame examples are fun and
helpful.  I now await my Raspberry-pi to see what stuff I can run on
it.  I assume it comes with Python3 in the bootable Fedora OS.  By the
time it comes, I thinnk I'll have found my way around Python to a usable
extent.

Regards,        Barry.

--
 From Barry Drake - a member of the Ubuntu advertising team.

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: [Tutor] breeds of Python .....

Barry Drake-2
In reply to this post by Alan Gauld
On 01/04/12 15:26, Alan Gauld wrote:
> Actually the standardization of C sparked huge debates in the early
> 90's. There were lots of minor changes and one big style change that
> really polarised opinions. In traditional C you defined a functions
> parameters like
>
> int foo()
> int a;
> float b;
> {  /* body here */  }

I started with c in the 1980s using Mix Power C under Microsoft DOS
3.5.  It was a number of years before I finished up with GCC under
Linux.  Power-C was the only version of c I worked with for several
years.  The input parameters were always inside the function brackets in
that version, so it must have been ansi-c.  I hadn't realised it was any
different from the K&R specs.  Interesting!

--
 From Barry Drake (The Revd) Health and Healing advisor to the East
Midlands Synod of the United Reformed Church.  See
http://www.urc5.org.uk/index for information about the synod, and
http://www.urc5.org.uk/?q=node/703 for the Synod Healing pages.

Replies - [hidden email]

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: [Tutor] breeds of Python .....

Alan Gauld
On 01/04/12 16:34, Barry Drake wrote:

> On 01/04/12 15:26, Alan Gauld wrote:
>> Actually the standardization of C sparked huge debates in the early
>> 90's. There were lots of minor changes and one big style change that
>> really polarised opinions. In traditional C you defined a functions
>> parameters like
>>
>> int foo()
>> int a;
>> float b;
>> { /* body here */ }

Oops, a slight mistake  there it should be:
int foo(a,b)
int a;
float b;
{ /* body here */ }

> I started with c in the 1980s using Mix Power C under Microsoft DOS 3.5.

I still have my Mix C compiler and manual (It runs under dosemu in Linux
:-), but mine was not "Power C"... and it came in dual CP/M
and MS DOS versions (I had a CP/M Computer too at the time). So I'm
guessing Power C was their ANSI version. I used it for years because I
could carry the whole thing, including IDE, on a single 720K floppy disk
- remember them! :-) Very handy for writing a quick ad-hoc tool
on a customers site. Exactly the kind of thing  I use python for nowadays!

> different from the K&R specs. Interesting!

Other differences included the introduction of
const for constants, the void type, and the // style line comment.
A lot of previously undefined behaviors became defined too. And the
library was expanded beyond all recognition, bringing in lots of
features that had been implementation dependant into the standard.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: [Tutor] breeds of Python .....

Alan Gauld
On 01/04/12 16:57, Alan Gauld wrote:
> On 01/04/12 16:34, Barry Drake wrote:

>> different from the K&R specs. Interesting!

A quick Google search threw up this useful PDF that does
a tour of the "new" features of ANSI C and how best to
use them.

http://www.sascommunity.org/sugi/SUGI88/Sugi-13-229%20Gass.pdf

Also the ANSI C standard was published in 1988 so
the arguments must have been mid-80s not early 90's.
How time flies...

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: [Tutor] breeds of Python .....

Barry Drake-2
In reply to this post by Alan Gauld
On 01/04/12 16:57, Alan Gauld wrote:
> Oops, a slight mistake  there it should be:
> int foo(a,b)
> int a;
> float b;
> { /* body here */ }

Ah, now that rings bells ....  It's all a very long time ago, but I
think my Power-C was able to accept either format and not complain.  I
still have my Power-C carefully preserved on a CD.  I'll have to dig it
out sometime and try it under DosBox emulator.  That seems to run most
ancient DOS stuff.  I think my version of Power-C came on a 5-1/4"
floppy and would run from there.  I seem to remember using it before I
had a computer with a hard-drive, just two 5-1/4" floppies.  Those were
the days!

Regards,        Barry.

--
 From Barry Drake - a member of the Ubuntu advertising team.

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: [Tutor] breeds of Python .....

Stefan Behnel-3
In reply to this post by Brett Ritter
Brett Ritter, 01.04.2012 07:19:
> On Sat, Mar 31, 2012 at 5:37 PM, Barry Drake wrote:
>> concentrate on Python3 or stay with Python2 and get into bad habits when it
>> comes to change eventually?  Apart from the print and input functions, I
>> haven't so far got a lot to re-learn.
>
> My recommendation is to go with Python2 - most major projects haven't
> made the switch

This statement is a bit misleading because it implies that you actually
"have to make the switch" at some point. Many projects are quite happily
supporting both at the same time, be it in a single code base (e.g. helped
by the "six" module) or by using the 2to3 conversion tool.

Also, from what I see and hear, "most major projects" are at least on their
way to adapting their code base for Python 3 compatibility, and many, many
libraries and other small or large software packages are already available
for Python 3.

I don't see a major reason for a beginner to not go straight for Python 3,
and then learn the necessary Py2 quirks in addition when the need arises.

Stefan

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: [Tutor] breeds of Python .....

Barry Drake-2
On 01/04/12 18:16, Stefan Behnel wrote:
> I don't see a major reason for a beginner to not go straight for
> Python 3, and then learn the necessary Py2 quirks in addition when the
> need arises.

Thanks for that.  Really re-assuring.  Also, I hadn't looked at 2to3
until you mentioned it - and certainly I hadn't realised that I already
have it as part of python3.  Most of the simple examples that I would
want to use should convert using 2to3 'out of the box'.  Thanks.

Regards,        Barry.

--
 From Barry Drake - a menber of the Ubuntu advertising team.

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: [Tutor] breeds of Python .....

Wayne Werner-2
In reply to this post by modulok-2
On Sat, 31 Mar 2012, Modulok wrote:
> If you're just starting out, go with 3.x. If you have a need for some third
> party modules that aren't yet available for 3.x, you'll have to stick with 2.x.

For a handy list, check out the Python3 Wall of Shame (soon to be superpowers?)
http://python3wos.appspot.com/

HTH,
Wayne
_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor