Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102204

Re: psss...I want to move from Perl to Python

From Cameron Simpson <cs@zip.com.au>
Newsgroups comp.lang.python
Subject Re: psss...I want to move from Perl to Python
Date 2016-01-29 12:20 +1100
Message-ID <mailman.71.1454030466.2338.python-list@python.org> (permalink)
References <n8ea4q$muu$1@gioia.aioe.org>

Show all headers | View raw


On 28Jan2016 19:01, Fillmore <fillmore_remove@hotmail.com> wrote:
>I learned myself Perl as a scripting language over two decades ago.  All 
>through this time, I would revert to it from time to time whenever I needed 
>some text manipulation and data analysis script.
>
>My problem? maybe I am stupid, but each time I have to go back and 
>re-learn the syntax, the gotchas, the references and the derefercing, 
>the different syntax between Perl 4 and Perl 5, that messy CPAN in 
>which every author seems to have a different ideas of how things 
>should be done....

Yes. CPAN always seemed a royal PITA to me too. Pip and Python virtualenvs are 
much cleaner IMO.

>I look and Python and it looks so much more clean....

Oh yes. I wasted quite a while with Perl before shifting, largely because I had 
a large base of personal Perl modules I used a lot and felt like the bootstrap 
process would be painful. I do wish I'd jumped in a few years earlier.

>Does Python have Regexps?

It has a regexp module named "re" and they're the same syntax as perl. It 
doesn't have regexp operations as part of the language itself (no "=~ /regexp/" 
stuff) - you compile a regexp and then use it. This does mean you use regexps 
more deliberately and less frequently than in Perl, but that is a Good Thing.  
Regexps are far far overused in Perl and elsewhere. They are cumbersome, 
cryptic and error prone. Python's strings have a bunch of fixed-string methods 
available which cover a surprisingly large number of cases before you need the 
complexity of a regexp.

>How was the Python 2.7 vs Python 3.X solved? which version should I go for?

Go for 3. While not everything has been ported, many many things have and you 
will mostly be fine. Python 3 has a much cleaner bytes vs text separation 
(which is also a Good Thing), some library cleanups, and all the new work goes 
to Python 3. Python 2 exists, but is essentially frozen. I try to write code 
which will work in both (easy most of the time), but some of my code will only 
work in Python 3 because it works with bytes and text, and going back to the 
ambiguity of Python 2 would be a disaster (in fact, the module I'm thinking of 
had many potential bugs which got cleaned up as a direct result of the move to 
3).

>Do you think that switching to Python from Perl is a good idea at 45?

Yes. Yes yes yes.

>Where do I get started moving from Perl to Python?

There are tutorials, if that kind of thing works for you. My approach was to 
just start writing small things in Python. And when those things got reused, 
start making them modules (== "packages" in Perl speak). You will end up with a 
little suite of tools.

Also, join the "tutor@python.org" list. That is where to go for new Pythoners 
seeking help.

>which gotchas need I be aware of?

Hard to say, I found it depended on what I was doing.

I think the biggest for all new users is probably the "default argument value" 
semantics. When you write a Python function:

  def foo(a, b):
    ...

you can specify default values. For example:

  def (a, b=3):
    ...

means you can call foo as foo(1) and it will be like calling it as foo(1, 3).  
The important point here is that the default values are computed at function 
definition time, _not_ at function call time. For constants like the above this 
doesn't matter, but consider this:

  def foo(a, b=[]):

so that "b" defaults to being an empty list. Because "[]" is computed when the 
function is defined, you will be reusing the _same_ list whenever you call the 
function without specifying "b"; it won't stay an empty list, becuase it is not 
a _new_ empty list of each call.

So if you had "b.append(4)" inside the function, the list would progressively 
accrue 4s, and so forth. For this reason the standard idiom for default 
arguments goes:

  def foo(a, b=None):
    if b is None:
      b = []

Since that test runs on each call (being inside the function), it does make a 
new empty list for "b" if it was not specified.

Cheers,
Cameron Simpson <cs@zip.com.au>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

psss...I want to move from Perl to Python Fillmore <fillmore_remove@hotmail.com> - 2016-01-28 19:01 -0500
  Re: psss...I want to move from Perl to Python paul.hermeneutic@gmail.com - 2016-01-28 17:22 -0700
  Re: psss...I want to move from Perl to Python Nathan Hilterbrand <nhilterbrand@gmail.com> - 2016-01-28 19:21 -0500
    Re: psss...I want to move from Perl to Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-01-28 19:23 -0800
      Re: psss...I want to move from Perl to Python Chris Angelico <rosuav@gmail.com> - 2016-01-29 14:26 +1100
    Re: psss...I want to move from Perl to Python wxjmfauth@gmail.com - 2016-01-30 02:26 -0800
      Re: psss...I want to move from Perl to Python Fillmore <fillmore_remove@hotmail.com> - 2016-01-31 17:34 -0500
        Re: psss...I want to move from Perl to Python Michael Torrie <torriem@gmail.com> - 2016-01-31 16:45 -0700
        Re: psss...I want to move from Perl to Python Chris Angelico <rosuav@gmail.com> - 2016-02-01 10:48 +1100
        Re: psss...I want to move from Perl to Python Terry Reedy <tjreedy@udel.edu> - 2016-01-31 18:51 -0500
          Re: psss...I want to move from Perl to Python Rustom Mody <rustompmody@gmail.com> - 2016-01-31 18:59 -0800
            Re: psss...I want to move from Perl to Python Chris Angelico <rosuav@gmail.com> - 2016-02-01 14:15 +1100
              Re: psss...I want to move from Perl to Python Rustom Mody <rustompmody@gmail.com> - 2016-01-31 19:43 -0800
              Re: psss...I want to move from Perl to Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-02-02 14:53 -0800
  Re: psss...I want to move from Perl to Python Chris Angelico <rosuav@gmail.com> - 2016-01-29 11:25 +1100
    Re: psss...I want to move from Perl to Python Steven D'Aprano <steve@pearwood.info> - 2016-01-29 18:12 +1100
      Re: psss...I want to move from Perl to Python Chris Angelico <rosuav@gmail.com> - 2016-01-29 18:19 +1100
      Re: psss...I want to move from Perl to Python Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2016-01-29 09:12 +0000
        Re: psss...I want to move from Perl to Python James Harris <james.harris.1@gmail.com> - 2016-01-29 11:03 +0000
          Re: psss...I want to move from Perl to Python Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2016-01-29 12:21 +0000
            Re: psss...I want to move from Perl to Python Steven D'Aprano <steve@pearwood.info> - 2016-01-30 00:46 +1100
              Re: psss...I want to move from Perl to Python Ben Finney <ben+python@benfinney.id.au> - 2016-01-30 09:47 +1100
                Re: psss...I want to move from Perl to Python Steven D'Aprano <steve@pearwood.info> - 2016-01-30 22:12 +1100
            Re: psss...I want to move from Perl to Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-01-29 13:30 -0800
              Re: psss...I want to move from Perl to Python Fillmore <fillmore_remove@hotmail.com> - 2016-01-29 19:57 -0500
                Re: psss...I want to move from Perl to Python Ben Finney <ben+python@benfinney.id.au> - 2016-01-30 12:04 +1100
              Re: psss...I want to move from Perl to Python Rustom Mody <rustompmody@gmail.com> - 2016-01-29 19:38 -0800
                Re: psss...I want to move from Perl to Python Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-01-31 11:18 +1300
                Re: psss...I want to move from Perl to Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-01-31 12:56 +1100
                Re: psss...I want to move from Perl to Python Rustom Mody <rustompmody@gmail.com> - 2016-01-30 19:22 -0800
                Re: psss...I want to move from Perl to Python Cameron Simpson <cs@zip.com.au> - 2016-01-31 14:48 +1100
                Re: psss...I want to move from Perl to Python Rustom Mody <rustompmody@gmail.com> - 2016-01-30 19:53 -0800
                Re: psss...I want to move from Perl to Python Cameron Simpson <cs@zip.com.au> - 2016-01-31 20:56 +1100
                Re: psss...I want to move from Perl to Python Paul Rubin <no.email@nospam.invalid> - 2016-01-31 09:45 -0800
                Re: psss...I want to move from Perl to Python Rustom Mody <rustompmody@gmail.com> - 2016-01-31 18:08 -0800
                Re: psss...I want to move from Perl to Python Steven D'Aprano <steve@pearwood.info> - 2016-01-31 20:23 +1100
                Re: psss...I want to move from Perl to Python Cameron Simpson <cs@zip.com.au> - 2016-01-31 20:53 +1100
                Re: psss...I want to move from Perl to Python Paul Rubin <no.email@nospam.invalid> - 2016-01-31 09:49 -0800
                Re: psss...I want to move from Perl to Python Cameron Simpson <cs@zip.com.au> - 2016-02-01 08:16 +1100
                Re: psss...I want to move from Perl to Python Terry Reedy <tjreedy@udel.edu> - 2016-01-31 07:28 -0500
                Re: psss...I want to move from Perl to Python Rustom Mody <rustompmody@gmail.com> - 2016-01-31 05:12 -0800
                Re: psss...I want to move from Perl to Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-01-30 14:25 -0800
              Re: psss...I want to move from Perl to Python Rustom Mody <rustompmody@gmail.com> - 2016-01-29 20:04 -0800
        Re: psss...I want to move from Perl to Python Random832 <random832@fastmail.com> - 2016-01-29 10:07 -0500
          Re: psss...I want to move from Perl to Python Fillmore <fillmore_remove@hotmail.com> - 2016-01-29 12:56 -0500
          Re: psss...I want to move from Perl to Python Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-01-30 11:21 +1300
        Re: psss...I want to move from Perl to Python sohcahtoa82@gmail.com - 2016-01-29 12:49 -0800
          Re: psss...I want to move from Perl to Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-01-29 14:29 -0800
      Re: psss...I want to move from Perl to Python Cameron Simpson <cs@zip.com.au> - 2016-01-30 10:48 +1100
  Re: psss...I want to move from Perl to Python Cameron Simpson <cs@zip.com.au> - 2016-01-29 12:20 +1100
  Re: psss...I want to move from Perl to Python Paul Rubin <no.email@nospam.invalid> - 2016-01-28 18:06 -0800
    Re: psss...I want to move from Perl to Python Chris Angelico <rosuav@gmail.com> - 2016-01-29 13:34 +1100
      Re: psss...I want to move from Perl to Python sohcahtoa82@gmail.com - 2016-01-29 12:41 -0800
        Re: psss...I want to move from Perl to Python Chris Angelico <rosuav@gmail.com> - 2016-01-30 07:54 +1100
        Re: psss...I want to move from Perl to Python Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-01-30 11:27 +1300
    Re: psss...I want to move from Perl to Python Michael Torrie <torriem@gmail.com> - 2016-01-28 21:42 -0700
    Re: psss...I want to move from Perl to Python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-01-29 08:54 -0500
  Re: psss...I want to move from Perl to Python Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-01-29 08:24 +0200
  Re: psss...I want to move from Perl to Python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-01-29 08:50 -0500
  Re: psss...I want to move from Perl to Python Fillmore <fillmore_remove@hotmail.com> - 2016-01-29 12:04 -0500
  Re: psss...I want to move from Perl to Python "Sven R. Kunze" <srkunze@mail.de> - 2016-01-29 18:39 +0100
  Re: psss...I want to move from Perl to Python Fillmore <fillmore_remove@hotmail.com> - 2016-01-29 15:42 -0500
    Re: psss...I want to move from Perl to Python Chris Angelico <rosuav@gmail.com> - 2016-01-30 07:51 +1100
    Re: psss...I want to move from Perl to Python Nathan Hilterbrand <nhilterbrand@gmail.com> - 2016-01-29 16:38 -0500
    Re: psss...I want to move from Perl to Python Cody Piersall <cody.piersall@gmail.com> - 2016-01-29 15:50 -0600
      Re: psss...I want to move from Perl to Python Josef Pktd <josef.pktd@gmail.com> - 2016-01-29 16:48 -0800
    Re: psss...I want to move from Perl to Python Terry Reedy <tjreedy@udel.edu> - 2016-01-29 22:08 -0500
    Re: psss...I want to move from Perl to Python Chris Angelico <rosuav@gmail.com> - 2016-01-30 14:12 +1100
  Re: psss...I want to move from Perl to Python Ben Finney <ben+python@benfinney.id.au> - 2016-01-30 09:49 +1100
  Re: psss...I want to move from Perl to Python Larry Hudson <orgnut@yahoo.com> - 2016-01-29 22:22 -0800
  Re: psss...I want to move from Perl to Python "Sven R. Kunze" <srkunze@mail.de> - 2016-01-30 13:43 +0100
  Re: psss...I want to move from Perl to Python <paul.hermeneutic@gmail.com> - 2016-02-02 10:00 -0700
  Re: psss...I want to move from Perl to Python "Martin A. Brown" <martin@linux-ip.net> - 2016-02-02 13:04 -0800
  Re: psss...I want to move from Perl to Python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-02-02 19:36 -0500

csiph-web