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 3959
> "Thomas Guettler" <gu*****@thom as-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("som e complaint")
--Scott David Daniels Sc***********@A cm.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">
However, I have found that I can use an alternate file extension, such as
<script src="foo.HTML" type="text/javascript">
It works fine with my IE 6 and Mozilla. Will it work with other browsers?
|
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 foo {
};
|
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 = ConfigurationSettings.AppSettings
Once your application has called for the "foo" key once, how expensive is to
call the same line again? My gut tells me that the CLR likely stores these
values in memory in a string dictionary or similar. Looking up the value
requires the...
| |
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. Umpteen
hours into a run, an assertion failed, and of course since failure
was "impossible", I didn't catch the exception so the whole program
crashed. I don't know what I'd have done with the exception anyway,
since it would have had to be...
|
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 = fooVar.constructor == String;
|
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 author states that the instanceof operator computes its result
|
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 domain
".foo.com" (foo is not the actual domain name, of course). The HTTP
response which made that cookie was something like,
SET-COOKIE : ...., domain : foo.com;
Now, I wanted to retrieve that cookie value, but all these failed,
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |