Writing one-liners in Python (was: Re: [Tutor] help mee)

Rogério Brito linuxconsult@yahoo.com.br
Wed, 1 May 2002 22:56:17 -0300


On May 01 2002, Del Kollhoff wrote:
> how do you put a plain text program into python command line?

	Perhaps you should use the -c option of the python
	interpreter? Something like:

	$ python -c 'print "a"'

	But I'd like to use your question as a starting point for a
	question of mine.

	Unfortunately, I have the impression that writing one-liners
	in Python isn't as easy as writing one-liners in Perl (for me
	at least -- I am still a newbie in Python).  The reason for my
	impression is that there aren't block delimiters like C's or
	Perl's "{" and "}" available in Python.

	As a result, I don't know how one would convert to a
	one-liner, say, something along the lines of the following
	code:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	while (cond1 and cond2):
	    # do something

	# now, which condition failed? cond1 or cond2?
	if (cond1):
	    # cond2 failed and cond2 didn't
        else:
            # cond1 failed
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	So, while converting this to a one-liner, how does one
	indicate to that the if is not contained within the while
	loop?

	Any help with this issue would be more than welcome.


	Thanks in advance, Roger...

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  Rogério Brito - rbrito@iname.com - http://www.ime.usp.br/~rbrito/
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=