[Tutor] Hello, and a newbie question
Dave Angel
davea at davea.name
Tue Apr 16 22:18:16 CEST 2013
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
More information about the Tutor
mailing list