Translating a Perl script into Python

Alex Martelli aleaxit at yahoo.com
Sat Jan 20 17:16:23 EST 2001


"Sheila King" <sheila at thinkspot.net> wrote in message
news:1tej6tgp30shi14sgr7908f3l8vd5qkp59 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()
    [snip]
> 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()
    [snip]
> 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")
    [snip]
> Thanks for the tips. This was one thing I felt was quite awkward about the
> Python script as compared to the original Perl script.

You're welcome -- I had suspected you would, because having to repeat
the quotes left me somewhat cold back when I was converting all of my Perl
scripts over to Python, until I thought of using string.split (back in 1.5.2
times -- with 2.0, the split method of the string is even better).


Alex






More information about the Python-list mailing list