From: D-Man <ds...@ri...> - 2001-03-29 15:09:45
|
Ype and I discussed the syntax of assert (and raise) a bit off the list. I am now forwarding the discussion to the list (as requested) in case anyone else is interested. ----- Forwarded message from D-Man <ds...@ri...> ----- From: D-Man <ds...@ri...> Date: Wed, 28 Mar 2001 16:22:53 -0500 To: Ype Kingma <yk...@xs...> User-Agent: Mutt/1.2.5i On Wed, Mar 28, 2001 at 10:19:50PM +0100, Ype Kingma wrote: | -D, | | >On Wed, Mar 28, 2001 at 09:21:19PM +0100, Ype Kingma wrote: | >| | >| "Robert W. Bill" wrote: | >| > | >| > assert(test(stringtest, S[1])), "String test failed" | >| > | >| | >| Also the assert code is a bit strange: | >| 'assert' is a keyword, not a function. | >| Leaving out one pair of brackets gives: | > | >Robert has already mentioned that his post was hasty and had several | >errors in it. The posted line is harder to read due to the lack of | >whitespace between 'assert' and '('. Anyways, just FYI, assert can | | Sorry for that, I assumed the whole history was there... No problem. | >take a 2-tuple as its only "argument" | > | >assert ( 0 , "Hello World" ) | > | >is equivalent to | > | >assert 0 , "Hello World" | > | >It is quite useful when the expression, or more often, the string is | >too long. By using parens to create a tuple the \ prior to the | >newline is not necessary. | | Useful indeed. I rechecked the (python) docs on the assert statement, but | the tuple argument isn't mentioned there. Is there documentation | for it somewhere? I don't know. I have noticed that several keywords that take 2 "arguments" (like 'raise' for example) can take a 2-tuple instead. I tried it with assert and it worked. Now that I think about it, I think it is actually caused by the lexer/parser that expressions of the form <foo> , <bar> are tuples, and also ( <foo> , <bar> ) is the same tuple. I just took a look at http://www.python.org/doc/current/ref/parenthesized.html and the last paragraph seems most relevant. I guess assert and raise take a 2-tuple which can optionally have parenthesis or not. I use the parens when I want to break it over multiple lines without using \, but I put a space so it doesn't look like a function call. -D ----- End forwarded message ----- |