Migrating to perl?

Steve Lamb grey at despair.rpglink.com
Fri Jan 5 04:01:35 EST 2001


On Fri, 5 Jan 2001 00:47:32 -0500, Joel Ricker <joejava at dragonat.net> wrote:
>I've mentioned before that I'm real new to OO.  How should I approach it in
>Python?  Has anyone learned OO just from Python?  

    I have.  I hopped over from Perl to Python and while I still am employed
for my Perl expertise I try to use Python for personal use whenever possible.  
It took me about 2 weeks to port over one of my common learning projects using
my Perl code as a reference.  Was actually quite a joy.  I ended up using some
basic OO quite nicely.  In my experience Python makes it quite intuative.

>I heard something about curley braces as well.  No {} for blocks?  Thats
>going to take some getting used to :)

    No braces for blocks and intention matters.  For example...

if something:
  print "foo"
  print "bar"

...and...

if something:
  print "foo"
print "bar"

    ...do two different things.  The former will print foo and bar on two
separate lines only if something is true.  The latter will pring foo only if
something is true but will always print bar.

    The nice thing is that the interpretor is interactive so you can easily
play with the code.  Taking the above and actually defining something yields
the results.


{grey at teleute:/etc} python
Python 1.5.2 (#0, Apr  3 2000, 14:46:48)  [GCC 2.95.2 20000313 (Debian
GNU/Linux)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> something = 0
>>> if something:
...   print "foo"
...   print "bar"
... 
>>> if something:
...   print "foo"
... 
>>> print "bar"
bar
>>> 

    While Perl lets you write the script as you go Python implements command
history and line editing which Perl doesn't.  This lets you play with the code
in something like a shell setting and really lessens the learning curve
immensely.  When I was porting the script over I had one window open to the
Perl code for reference on logic, one open to vim to edit the script, one open
to Python so I could test out ideas to see if how I was reading my book was
really what the language did.  :)

-- 
         Steve C. Lamb         | I'm your priest, I'm your shrink, I'm your
         ICQ: 5107343          | main connection to the switchboard of souls.
-------------------------------+---------------------------------------------



More information about the Python-list mailing list