Re: [Tutor] Hello, and a newbie question

2013-04-19 Thread Prasad, Ramit
eryksun wrote:
 On Tue, Apr 16, 2013 at 7:57 PM, Virgilio Rodriguez Jr
 virgiliorodrigue...@gmail.com wrote:
  Can someone please do me the favor and remove me from this god forsaken
  email list I am sorry I signed up all it has done is taken over my phone and
  rings all night long with emails I am not interested in any more because it
  is just too many darn emails. I keep trying to log in and nothing it will
  not let me unsubscribe and it is BS already.
 
 You can get a password reminder here:
 http://mail.python.org/mailman/options/tutor
 
 If you're sure that you have the correct password and still can't
 unsubscribe, then email the administrator, tutor-ow...@python.org.
 Alan Gauld is active in this thread, BTW, in case you happen to have
 read the admin page where it says Tutor list run by wescpy at
 gmail.com, alan.gauld at btinternet.com.

Or switch to digest mode which will email once a day with all the 
messages in it. Be glad you are not subscribed to the main Python 
mailing list as it is far more active than the tutor list. ;)


~Ramit


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello, and a newbie question

2013-04-16 Thread Alan Gauld

On 16/04/13 16:58, Andy McKenzie wrote:


1) Python 2.7 or 3.x?  I know I'm going to want to do some work with
NLTK (which appears to only have an alpha version out for Python 3), but
I've just gone through the hassle of dealing with an upgrade from PHP 4
to 5.3, and I'd rather not start learning something that's already
obsolete.  Any words of advice?


Upgrading from P2 to P3 is not too onerous but there will be some 
changes to make at some po9nt.
However P2 is the one to go for if you want to do anything industrial 
just now because not all the 3rd party libraries (like NLTK) are fully 
ported to v3 yet, including some pretty significant ones.


OTOH If you are only experimenting/learning then going with P3 will 
avoid any relearning in the future.



2) Best practices.  I have the WROX Press Beginning Python book,


Sorry, I've never even seen that one so can't comment...


http://docs.python.org?  I would assume that that would start putting
me in the right habits from the beginning... is that accurate,


Yes, for existing programmers new to Python the official tutor is nearly 
always the best place to start. You can fill in the gaps elsewhere 
later. And the tutor is pretty short and fast paced, you can just about 
get through it all in an afternoon - certainly in a day.


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

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello, and a newbie question

2013-04-16 Thread Dave Angel

On 04/16/2013 11:58 AM, Andy McKenzie wrote:

Hey folks.

I'm just starting to pick up Python, and I'd like to avoid some of the
mistakes I made in the past.  To elaborate on that, my primary
programming/scripting experience is PHP, with a little bit of Perl thrown
in.  Like so many people who write in PHP, I was entirely self-taught, and
would be the first to admit that a lot of what I've written is, well...
wrong.  It works, but it's sloppy and inefficient, because there were
standard constructions and solutions I just didn't know about.  I'd like to
avoid that with Python.



Welcome to the mailing list.  I expect you'll find Python a much cleaner 
language than the other two, though php has some definite convenience 
for its particular niche.





So:  my first two questions to the list.

1) Python 2.7 or 3.x?  I know I'm going to want to do some work with NLTK
(which appears to only have an alpha version out for Python 3), but I've
just gone through the hassle of dealing with an upgrade from PHP 4 to 5.3,
and I'd rather not start learning something that's already obsolete.  Any
words of advice?



If you have to use a library that's not available yet for 3.x, then you 
need to use 2.x  on the other hand, if you're learning now, maybe that 
library will be available by the time you actually need it.


For most people, I'd advise against trying to use a tutorial that 
targets a different version than you're running.  If you get frustrated 
quickly, you can get bogged down by the differences when you're just 
copying an exact program out of some book.


Python 3 in particular has spent some substantial effort cleaning up the 
warts, the biggest one being Unicode.  For beginning programmers using 
only ASCII, probably the main thing that'll bog you down is that print() 
is now a function, rather than a statement, so you need parentheses. 
But once you get used to seeing syntax error, you quickly get the hang 
of it.  And once you do, the function is much nicer.




2) Best practices.  I have the WROX Press Beginning Python book, which
targets Python 2.  Clearly that's of only limited value if I'm going to go
with Python 3, but it looks like it's at least going to be a good overview.
  But some of the stuff they do seems to be fairly personalized, rather than
trying to follow standards.  Should I just start out with the tutorial from
docs.python.org?  I would assume that that would start putting me in the
right habits from the beginning... is that accurate, or is there a better
way to go?

Thanks in advance,
   Andy McKenzie


I'd start with the python.org tutorial for the version you're trying to 
learn.  Get serious about trying everything, and don't try to absorb it 
all in one sitting, even though it can be done.


And use a text editor that helps you indent, or even that colorizes your 
code.  And when you just want to try things, use the interpreter 
directly.  It's amazing what you can learn directly from it.  You can 
ask the interpreter lots of questions about an object:


   help(obj)
   dir(obj)
   print( type(obj) )
   print( repr(obj) )

And don't forget to post here when you seem to be stuck.  Sometimes a 
well placed comment beats days of struggling.  When you do get an 
exception you don't understand, paste the whole thing, as well as the 
code you were trying.


Best of luck.



--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello, and a newbie question

2013-04-16 Thread Andy McKenzie
On Tue, Apr 16, 2013 at 4:18 PM, Dave Angel da...@davea.name wrote:

 On 04/16/2013 11:58 AM, Andy McKenzie wrote:

 Hey folks.

 I'm just starting to pick up Python, and I'd like to avoid some of the
 mistakes I made in the past.  To elaborate on that, my primary
 programming/scripting experience is PHP, with a little bit of Perl thrown
 in.  Like so many people who write in PHP, I was entirely self-taught, and
 would be the first to admit that a lot of what I've written is, well...
 wrong.  It works, but it's sloppy and inefficient, because there were
 standard constructions and solutions I just didn't know about.  I'd like
 to
 avoid that with Python.


 Welcome to the mailing list.  I expect you'll find Python a much cleaner
 language than the other two, though php has some definite convenience for
 its particular niche.




  So:  my first two questions to the list.

 1) Python 2.7 or 3.x?  I know I'm going to want to do some work with NLTK
 (which appears to only have an alpha version out for Python 3), but I've
 just gone through the hassle of dealing with an upgrade from PHP 4 to 5.3,
 and I'd rather not start learning something that's already obsolete.  Any
 words of advice?


 If you have to use a library that's not available yet for 3.x, then you
 need to use 2.x  on the other hand, if you're learning now, maybe that
 library will be available by the time you actually need it.

 For most people, I'd advise against trying to use a tutorial that targets
 a different version than you're running.  If you get frustrated quickly,
 you can get bogged down by the differences when you're just copying an
 exact program out of some book.

 Python 3 in particular has spent some substantial effort cleaning up the
 warts, the biggest one being Unicode.  For beginning programmers using only
 ASCII, probably the main thing that'll bog you down is that print() is now
 a function, rather than a statement, so you need parentheses. But once you
 get used to seeing syntax error, you quickly get the hang of it.  And once
 you do, the function is much nicer.



  2) Best practices.  I have the WROX Press Beginning Python book, which
 targets Python 2.  Clearly that's of only limited value if I'm going to go
 with Python 3, but it looks like it's at least going to be a good
 overview.
   But some of the stuff they do seems to be fairly personalized, rather
 than
 trying to follow standards.  Should I just start out with the tutorial
 from
 docs.python.org?  I would assume that that would start putting me in the
 right habits from the beginning... is that accurate, or is there a better
 way to go?

 Thanks in advance,
Andy McKenzie


 I'd start with the python.org tutorial for the version you're trying to
 learn.  Get serious about trying everything, and don't try to absorb it all
 in one sitting, even though it can be done.

 And use a text editor that helps you indent, or even that colorizes your
 code.  And when you just want to try things, use the interpreter directly.
  It's amazing what you can learn directly from it.  You can ask the
 interpreter lots of questions about an object:

help(obj)
dir(obj)
print( type(obj) )
print( repr(obj) )

 And don't forget to post here when you seem to be stuck.  Sometimes a well
 placed comment beats days of struggling.  When you do get an exception you
 don't understand, paste the whole thing, as well as the code you were
 trying.

 Best of luck.




Thanks for the advice, folks.  Given that it looks like the biggest changes
are unicode handling (which I'm not going to need any time soon) and the
way the print function works, I decided to stick with 2.7.  I'm an IT guy,
though unemployed at the moment, and it occurred to me that I'm familiar
with Python, but not the version your entire established codebase is in
wasn't a great thing to have on a resume.

Since it looks like the new formatting for print -- that is, print(Print
this stuff!) -- works fine in 2.7, I'm just getting myself used to doing
that from the beginning.

I went through the first four or five sections of the tutorial this
afternoon, with a few side trips into things that got me interested, and I
figure I'll do at least one more section after dinner.  I did find it
interesting that one of the first things I wanted to know turned out to be
an extremely common question:  What's the Python equivalent to print_r()
from PHP?  If any of you are familiar with PHP (I know at least a couple
of you seemed to be), you'll know that pprint() (which seems to be the most
common answer) isn't actually very close.  Its output isn't nearly as
readable.

For instance:  output of running print_r on a very short dictionary from
PHP:

Array
(
[key3] = thing3
[key2] = thing2
[key1] = thing1
)

And running pprint on the same dict in Python:

{'key1': 'thing1', 'key2': 'thing2', 'key3': 'thing3'}


I finally decided that a good project would be building a quick function
that recreates the print_r 

Re: [Tutor] Hello, and a newbie question

2013-04-16 Thread Dave Angel

On 04/16/2013 05:20 PM, Andy McKenzie wrote:




SNIP




Thanks for the advice, folks.  Given that it looks like the biggest changes
are unicode handling (which I'm not going to need any time soon) and the
way the print function works, I decided to stick with 2.7.  I'm an IT guy,
though unemployed at the moment, and it occurred to me that I'm familiar
with Python, but not the version your entire established codebase is in
wasn't a great thing to have on a resume.

Since it looks like the new formatting for print -- that is, print(Print
this stuff!) -- works fine in 2.7, I'm just getting myself used to doing
that from the beginning.



The degenerate print, where you're printing exactly one thing, works the 
same.  But if you have two things to print, putting parens around them 
in Python 2.x will cause a tuple to be printed, rather than printing the 
two with a space between.


 print(3,5)  -- version 2.x
(3, 5)

 print(3,5)  -- version 3.x
3 5

To get 3.x functionality, you'd want to use
from __future__ import print_function

and I do not think that works in 2.6 or older versions.  It also can be 
awkward even in 2.7 if you're mixing existing code with new print functions.




--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello, and a newbie question

2013-04-16 Thread Andy McKenzie
On Tue, Apr 16, 2013 at 5:31 PM, Dave Angel da...@davea.name wrote:

 On 04/16/2013 05:20 PM, Andy McKenzie wrote:



  SNIP



  Thanks for the advice, folks.  Given that it looks like the biggest
 changes
 are unicode handling (which I'm not going to need any time soon) and the
 way the print function works, I decided to stick with 2.7.  I'm an IT guy,
 though unemployed at the moment, and it occurred to me that I'm familiar
 with Python, but not the version your entire established codebase is in
 wasn't a great thing to have on a resume.

 Since it looks like the new formatting for print -- that is, print(Print
 this stuff!) -- works fine in 2.7, I'm just getting myself used to doing
 that from the beginning.


 The degenerate print, where you're printing exactly one thing, works the
 same.  But if you have two things to print, putting parens around them in
 Python 2.x will cause a tuple to be printed, rather than printing the two
 with a space between.

  print(3,5)  -- version 2.x
 (3, 5)

  print(3,5)  -- version 3.x
 3 5

 To get 3.x functionality, you'd want to use
 from __future__ import print_function

 and I do not think that works in 2.6 or older versions.  It also can be
 awkward even in 2.7 if you're mixing existing code with new print functions.


That's good to know, since I hadn't run into it yet.

So am I correct in understanding that I can just put the from __future__
import print_function in each new 2.7 script, and get identical
functionality to what happens in 3.x?  Or do I need to do that system-wide
somehow?

-Andy
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello, and a newbie question

2013-04-16 Thread Dave Angel

On 04/16/2013 05:47 PM, Andy McKenzie wrote:

On Tue, Apr 16, 2013 at 5:31 PM, Dave Angel da...@davea.name wrote:


SNIP

To get 3.x functionality, you'd want to use
 from __future__ import print_function

and I do not think that works in 2.6 or older versions.  It also can be
awkward even in 2.7 if you're mixing existing code with new print functions.



That's good to know, since I hadn't run into it yet.

So am I correct in understanding that I can just put the from __future__
import print_function in each new 2.7 script, and get identical
functionality to what happens in 3.x?  Or do I need to do that system-wide
somehow?



Someone else may know if identical has some exceptions.  But as for 
where to put it, you'd need it for any module (including your own 
script) which is going to use the newer print() function.


And the nice thing is that the from-future directive is ignored in 3.x, 
so you don't have to remove it when you do progress.


--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello, and a newbie question

2013-04-16 Thread Alan Gauld

On 16/04/13 22:20, Andy McKenzie wrote:


For instance:  output of running print_r on a very short dictionary from
PHP:

Array
(
 [key3] = thing3
 [key2] = thing2
 [key1] = thing1
)

And running pprint on the same dict in Python:

{'key1': 'thing1', 'key2': 'thing2', 'key3': 'thing3'}


I finally decided that a good project would be building a quick function
that recreates the print_r function, and I got that working.  New
function output, in Python:

(
 [key3] = thing3
 [key2] = thing2
 [key1] = thing1
)



You should probably use {} instead of () as the delimiter to indicate 
that the thing is a dictionary and not a tuple. but otherwise that's a 
good starter project.



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

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello, and a newbie question

2013-04-16 Thread eryksun
On Tue, Apr 16, 2013 at 6:17 PM, Dave Angel da...@davea.name wrote:
 Someone else may know if identical has some exceptions.  But as for where
 to put it, you'd need it for any module (including your own script) which is
 going to use the newer print() function.

I think any differences will result from the I/O system redesign in
3.x. In 2.x sys.stdout is still the old file type, which is
basically a wrapper around CRT FILE streams, while in 3.x it's a
TextIOWrapper wrapping a BufferedWriter wrapping a FileIO object.

Off the top of my head I don't have a clear example where it matters.
I vaguely recall having an issue with the default buffer flushing not
being the same. I think I was simulating scrolling text by printing a
carriage return ('\r') to overwrite a line. IRRC, in the end I opted
to directly use sys.stdout.write() and sys.stdout.flush().

Since __future__ imports are compiler directive, you have to include
them at the top of every module. print_function works in 2.6+. If
you just want the function under a different name, you can grab it
from the __builtin__ module:

 import __builtin__
 printf = getattr(__builtin__, 'print')
 printf('spam')
spam
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello, and a newbie question

2013-04-16 Thread Andy McKenzie
On Tue, Apr 16, 2013 at 7:39 PM, Alan Gauld alan.ga...@btinternet.comwrote:

 On 16/04/13 22:20, Andy McKenzie wrote:

  For instance:  output of running print_r on a very short dictionary from
 PHP:

 Array
 (
  [key3] = thing3
  [key2] = thing2
  [key1] = thing1
 )

 And running pprint on the same dict in Python:

 {'key1': 'thing1', 'key2': 'thing2', 'key3': 'thing3'}


 I finally decided that a good project would be building a quick function
 that recreates the print_r function, and I got that working.  New
 function output, in Python:

 (
  [key3] = thing3
  [key2] = thing2
  [key1] = thing1
 )



 You should probably use {} instead of () as the delimiter to indicate that
 the thing is a dictionary and not a tuple. but otherwise that's a good
 starter project.


Good idea.  I went with () because I was just trying to duplicate the
output in PHP.  Now that I've got that, I can start thinking about
improvements.  Varying the punctuation to match the type would probably be
a good idea.

Thanks,
  Andy
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello, and a newbie question

2013-04-16 Thread Steven D'Aprano

On 17/04/13 01:58, Andy McKenzie wrote:


1) Python 2.7 or 3.x?  I know I'm going to want to do some work with NLTK
(which appears to only have an alpha version out for Python 3), but I've
just gone through the hassle of dealing with an upgrade from PHP 4 to 5.3,
and I'd rather not start learning something that's already obsolete.  Any
words of advice?


Python 3.3 is awesome and much cleaner and better than 2.7, and 2.7 is
pretty damn good! So if you have a choice, pick 3.3. It's the future of
Python, 2.7 is the past.

But, 2.7 is still good, and if you need NLTK *right now* you might not have
a choice. (Unless you like being a guinea pig working with an alpha version.)

Also, the *incompatibilities* between 2.7 and 3.3 are fairly small. The
biggest difference from a beginner's perspective is that print is no longer
a statement, it is a function, so instead of writing this:

print Hello world!

you have to write this:

print(Hello world!)

That doesn't seem too onerous, does it? If you can cope with a few differences
of that complexity, why not learn both?



2) Best practices.  I have the WROX Press Beginning Python book, which
targets Python 2.  Clearly that's of only limited value if I'm going to go
with Python 3, but it looks like it's at least going to be a good overview.
  But some of the stuff they do seems to be fairly personalized, rather than
trying to follow standards.  Should I just start out with the tutorial from
docs.python.org?  I would assume that that would start putting me in the
right habits from the beginning... is that accurate, or is there a better
way to go?


If there's a Python 3 version of Learning Python, from O'Reilly Books (sorry
I forget the authors), give it a go. The first edition, at least, is an awesome
book although you will want a more recent version since the first edition
deals with Python 1.5, which truly is ancient history!

I haven't done the official Python tutorial, but from what I've seen of it,
it's pretty good.



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello, and a newbie question

2013-04-16 Thread eryksun
On Tue, Apr 16, 2013 at 7:57 PM, Virgilio Rodriguez Jr
virgiliorodrigue...@gmail.com wrote:
 Can someone please do me the favor and remove me from this god forsaken
 email list I am sorry I signed up all it has done is taken over my phone and
 rings all night long with emails I am not interested in any more because it
 is just too many darn emails. I keep trying to log in and nothing it will
 not let me unsubscribe and it is BS already.

You can get a password reminder here:
http://mail.python.org/mailman/options/tutor

If you're sure that you have the correct password and still can't
unsubscribe, then email the administrator, tutor-ow...@python.org.
Alan Gauld is active in this thread, BTW, in case you happen to have
read the admin page where it says Tutor list run by wescpy at
gmail.com, alan.gauld at btinternet.com.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello, and a newbie question

2013-04-16 Thread eryksun
On Tue, Apr 16, 2013 at 8:15 PM, eryksun eryk...@gmail.com wrote:
 Can someone please do me the favor and remove me from this god forsaken
 email list I am sorry I signed up all it has done is taken over my phone and
 rings all night long with emails I am not interested in any more because it
 is just too many darn emails. I keep trying to log in and nothing it will
 not let me unsubscribe and it is BS already.

 You can get a password reminder here:
 http://mail.python.org/mailman/options/tutor

 If you're sure that you have the correct password and still can't
 unsubscribe, then email the administrator, tutor-ow...@python.org.
 Alan Gauld is active in this thread, BTW, in case you happen to have
 read the admin page where it says Tutor list run by wescpy at
 gmail.com, alan.gauld at btinternet.com.

I just went through the steps. You don't even need your password.
Enter your email address in the bottom field of the list info page:

http://mail.python.org/mailman/listinfo/tutor

Click the button that says Unsubscribe or edit options. Then simply
click the Unsubscribe button in the middle of the options page.
You'll get a confirmation email with instructions to complete the
process.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello, and a newbie question

2013-04-16 Thread Sander Sweers
On 04/17/2013 02:34 AM, eryksun wrote:
 I just went through the steps. You don't even need your password.
 Enter your email address in the bottom field of the list info page:
 
 http://mail.python.org/mailman/listinfo/tutor
 
 Click the button that says Unsubscribe or edit options. Then simply
 click the Unsubscribe button in the middle of the options page.
 You'll get a confirmation email with instructions to complete the
 process.

Or send an e-mail to tutor-requ...@python.org with unsubscribe in the
subject.

~sander
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor