Hi,
Python 2.3.3 (#1, Feb 5 2005, 16:22:10) [GCC 3.3.3 (SuSE Linux)] on linux2 assert 0, "foo"
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AssertionError: foo assert(0, "foo")
If you use parenthesis for the assert statement, it never
raises an exception.
Up to now I raised strings, but since this is deprecated,
I switched to use the second argument for the assert
statement.
Is it possible to change future python versions, that
assert accept parenthesis?
Thomas
--
Thomas Güttler, http://www.thomas-guettler.de/ 3 3941
> "Thomas Guettler" <gu*****@thomas-guettler.de> wrote in message news:pa****************************@thomas-guettler.de... Hi,
Python 2.3.3 (#1, Feb 5 2005, 16:22:10) [GCC 3.3.3 (SuSE Linux)] on
linux2 assert 0, "foo"
Assert that 0 is true. If that fails, raise AssertionError("foo").
Traceback (most recent call last): File "<stdin>", line 1, in ? AssertionError: foo assert(0, "foo")
Assert that the tuple (0, "foo") is true. Non-empty tuples are always true.
If you use parenthesis for the assert statement, it never raises an exception.
Up to now I raised strings, but since this is deprecated, I switched to use the second argument for the assert statement.
Is it possible to change future python versions, that assert accept parenthesis?
As shown above, it does, but it doesn't do quite what you expected. For
further enlightenment, try the following and think through why each one
gives the results it does:
assert (), 'spam'
assert [], 'eggs'
assert {}, 'spam and eggs'
assert (0,), 'spam, spam, and eggs'
assert (0, "foo"), 'spam, spam, eggs, and spam'
assert 0, "foo", 'shrubbery'
The last will give a syntax error. Can you spot why?
Thomas
-- Thomas Güttler, http://www.thomas-guettler.de/
Thomas Guettler wrote: Hi,
Python 2.3.3 (#1, Feb 5 2005, 16:22:10) [GCC 3.3.3 (SuSE Linux)] on linux2
assert 0, "foo" Traceback (most recent call last): File "<stdin>", line 1, in ? AssertionError: foo assert(0, "foo")
If you use parenthesis for the assert statement, it never raises an exception.
Up to now I raised strings, but since this is deprecated, I switched to use the second argument for the assert statement.
Is it possible to change future python versions, that assert accept parenthesis?
You are confusing assert with raise.
assert test, text
behaves like:
if __debug__ and test:
raise AssertionError, text
As far as raise goes, where you have been writing:
raise "some complaint"
you could simply use:
raise ValueError, "some complaint"
or:
raise ValueError("some complaint")
--Scott David Daniels Sc***********@Acm.Org
Thomas Guettler wrote: Is it possible to change future python versions, that assert accept parenthesis?
It's possible, but extremely unlikely that it will ever happen. assert
is not a function, but a statement (like print). Statements don't use
parentheses; when you use parentheses, it considers that a tuple.
For example, if you try this with print:
print ("hello","world")
you see that in prints out a tuple value, rather than treating "hello"
and "world" as arguments. Same thing with assert.
--
CARL BANKS This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: David D. |
last post by:
Does the file extension matter when including a JavaScript file in an HTML
page?
Normally, one would include a JavaScript file in an HTML page using
<script src="foo.JS" type="text/javascript">...
|
by: Daniel |
last post by:
how to make sure a xsl document has valid xsl syntax? i tried loading it
into an xml document but that doesnt show syntax errors inside attributes
such as "foo/bar" vs "bar\foo"
|
by: vilhelm.sjoberg |
last post by:
Hello,
I am a resonably confident C programmer, but not very sure about the
dark corners of C++. Recently, I had G++ give me a strange error.
The program in question is in essence:
struct...
|
by: Rajesh |
last post by:
I was informed tht $SUBJECT was asked in M$ interview. Real imp. is no.
of ways to achive it.
mine sol. was....
int main()
{
if(printf("foo"))
{ ; }
else
{ ; }
|
by: Mark |
last post by:
Could someone provide me with details or a link on how the line of code
executes underneath the hood? Assume it's executed in an ASP.NET
application.
string blah =...
|
by: Paul Rubin |
last post by:
So I have some assert statements in my code to verify the absence of
some "impossible" conditions. They were useful in debugging and of
course I left them in place for "real" runs of the program. ...
|
by: dhtmlkitchen |
last post by:
Why does "foo" instanceof String return false?
It just seems counterintuitive to me.
I mean, sure, I can always check the constructor:
var fooVar = "foo";
var isString =...
|
by: kj |
last post by:
My book (Flanagan's JavaScript: The Definitive Guide, 5th ed.)
implies on page 111 that the following two constructs are equivalent:
( x.constructor == Foo )
and
( x instanceof Foo )
The...
|
by: Sin Jeong-hun |
last post by:
Hello.
I used the same CookieContainer for several consecutive WebRequests,
then I could see that it contains cookies for several domains. I
examined the private m_domains and it contains a...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| | |