Translating a Perl script into Python

Sheila King sheila at thinkspot.net
Sat Jan 20 11:32:08 EST 2001


On Sat, 20 Jan 2001 08:21:06 -0800, Sheila King <sheila at thinkspot.net> wrote
in comp.lang.python in article <heej6tcb6cukmqkcc319lasc6qiu4hqcv7 at 4ax.com>:

:On Sat, 20 Jan 2001 14:01:11 +0100, "Alex Martelli" <aleaxit at yahoo.com> wrote
:in comp.lang.python in article <94c2as0nei at news2.newsguy.com>:
:
::"Sheila King" <sheila at thinkspot.net> wrote in message
::news:vo9i6t04nhurgv2avmgoss4mg86ofcuhtv at 4ax.com...
::    [snip]
::> qmail = ["SENDER", "NEWSENDER", "RECIPIENT", "USER", "HOME", "HOST",
::"LOCAL",
::>     "EXT", "EXT2", "EXT3", "EXT4", "DTLINE", "RPLINE", "UFLINE"]
::
::Excellent, but perhaps closer to the original Perl might be
::
::qmail = 'SENDER NEWSENDER RECIPIENT USER HOME HOST LOCAL EXT EXT2 EXT3 \
::    EXT4 DTLINE RPLINE UFLINE'.split()
:
:Someone else sent me a similar suggestion in e-mail. Where is this documented?

I found the documentation, here:
http://www.python.org/doc/current/lib/string-methods.html

Looks like 2.0 has really beefed up the string features? I was using 1.5.2
before (until recently).

:Believe me, I have been going over the docs THOROUGHLY and often! Is this a
:Python 2.0 feature? Or does it go back further? (I am using 2.0 right now,
:however, my web host only has 1.5.1 installed for everyone's use. I want to
:write a script, hopefully, that will run for everyone on the server.)

OK, so I decided to try this out on my host.
Running their install of Python (1.5.1):

Python 1.5.1 (#1, Sep  3 1998, 22:51:17)  [GCC 2.7.2.3] on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> qmail="SENDER RECIPIENT EXT HOST".split()
Traceback (innermost last):
  File "<stdin>", line 1, in ?
AttributeError: 'string' object has no attribute 'split'
>>>  

Running my private install of 2.0 on the same host (but only I have access to
it):

Python 2.0 (#1, Jan 15 2001, 01:09:04)
[GCC 2.7.2.3] on linux2
Type "copyright", "credits" or "license" for more information.
>>> qmail="SENDER RECIPIEN EXT HOST".split()
>>> print qmail
['SENDER', 'RECIPIEN', 'EXT', 'HOST']
>>>   

On my host, with 1.5.1 the following works:

Python 1.5.1 (#1, Sep  3 1998, 22:51:17)  [GCC 2.7.2.3] on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import string
>>> qmail=string.split("SENDER RECIPIENT EXT HOST")
>>> print qmail
['SENDER', 'RECIPIENT', 'EXT', 'HOST']
>>> 

Thanks for the tips. This was one thing I felt was quite awkward about the
Python script as compared to the original Perl script.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/




More information about the Python-list mailing list