multiline prototyping on command line
greg andruk
gerglery at usa.net
Sat Oct 30 04:55:37 EDT 1999
Eric Smith <eric at fruitcom.com> wrote:
> I am am a perl programmer looking at Python and would like to know whether
> it is possible on the command line to test algorithms like I do in perl
> thusly:
> perl -e '$r="de";if ($r eq "whatever" or "de") {print "a match\n"}
Nitpick: I don't think the above is testing what you think it's
testing; it will always print "a match" regardless of $r's value.
I'll assume you meant `...($r eq "whatever" or $r eq "de")...' there.
Anyway, Python's not especially amenable to one-liners. Instead, it
has a really spiffy interactive mode you can leave running in a window
or spare console session that works like you probably wish `perl -d'
worked:
meowing:~$ pytest
Python 1.5.2+ (#2, Oct 25 1999, 05:27:05) [GCC 2.7.2.3] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> r = 'de'
>>> r in ('whatever', 'de')
1
>>> # and just for the heck of it...
... r == 'whatever' or 'de'
'de'
>>>
More information about the Python-list
mailing list