What is Python?

Tim Hammerquist tim at degree.ath.cx
Fri Sep 22 01:19:20 CEST 2000

Grant Griffin <g2 at seebelow.org> wrote:
> My bigger problem nowadays is accidentally putting single-quotes around
> strings in C.  (Either double- or single-quotes will work in Python, but
> I tend to use single-quotes because they make for less of that nasty
> "punctuation clutter" that I left Perl to get away from. <wink>)

I also prefer single-quotes, unless I'm quoting a real language.  I
don't like:

	"And God said unto the gerbil, \"Do not chew your owners table.\"."
	'It\'s not their table.'

and I very much like the _ability_ (but not duty) of defining my own quote
character in Perl:

	qq{And God said, "Are you talkin' to me?! Huh, $gerbil_name?!}

> I'm basically competant in them, but I've never really
> "mastered" them.  So I remain uncomfortable with them, and I always have
> to keep my handy reference chart at hand.

Nothing wrong with looking in the book.  One can guess, though, by your
discomfort with regexps, that you've not worked extensively in a *nix

> Actually, when I first took up Perl, I looked for something _like_
> Python's string module, but I found none;

Um, Perl built-ins:
	perldoc -f join
	perldoc -f split

Split on whitespace:
	@words = split $sentence;        # Perl
	words = string.split( sentence ) # Python

Split on ':':
	@attributes = split ':', $line_from_passwd;
	attributes = string.splitfields( line_from_passwd, ':' )

Split on any non-alphanumeric character:
	@alphas = split /\W/, $line;
	# Um...didn't find it in the string module

Join on ' ':
	$line = join ' ', @words;
	line = string.join( words )

Join on ':':
	$line = join ':', words;
	line = string.join( words )

Yes, I realize that splitting on non-alphanums required a regex, but the
fact that Perl's split supports regexps when called upon is definitely a

> the Camel book
> would win a Pulitzer Prize here if the Pulitizer folks had a category
> for "Worst Technical Writing" <0.1 wink>), but REs represent a major
> hurdle for beginners.

This is very true, and REs were a major hurdle for me as well.  I had to
buckle down and learn regexps as a separate concept before I could
really appreciate how Perl integrated them.  As far as the Camel goes,
this is not an infrequent thread in clpm.  The Camel is widely regarded
as a much better _reference_ than an instructional or tutorial book, and
I agree wholeheartedly.  I was unable to "learn" Perl from the Camel,
but since I grokked Perl, the Camel is invaluable.

> To be fair, though, one of the few things I miss about Perl is its easy
> use of REs: that's obviously one of its great strengths.  However,
> Python's approach of providing that same functionality as a module, not
> as a fundamental language feature, is definitely more "Pythonic": the
> result is significantly more verbose, but that's exactly the point:
> there's quite a lot of "implicit is worse than explicit" (to coarsely
> paraphrase) baggage that comes along with Perl's approach.

This is probably one of the side-effects of Larry's styling Perl after
natural language.  I should say that I'm not only a computer language
fan, but also a foreign language major with several Romance languages as
a hobby.  Might that be why my mind appears *twisted* in liking Perl's

> i-heard-somewhere-that-this-is-level-of-modularity-one-of-the
>    -major-design-goals-of-the-TBD-perl6-<wink>-ly y'rs,

-Tim Hammerquist <timmy at cpan.org>

Legend -- a lie that has attained the dignity of age.
	-- H. L. Mencken

More information about the Python-list mailing list