473,783 Members | 2,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to modify meaning of builtin function "not" to "!"?

I am creating functions, the return result of which I am using to make
decisions in combined expressions.
In some expressions, I would like to inverse the return result of
function.

E.g. function contains(source ,search) will return true if "search"
string is found in source string.
I want to make reverse of this by putting it as:
if ( ! contains(s1,s2) ):
return 1

I found that "!" is not accepted by Python & compile fails with
"invalid syntax".
Corresponding to this Boolean Operator we've "not" in Python.

How can I make "not" as "!"?
Jun 27 '08 #1
6 1761
grbgooglefan wrote:
I am creating functions, the return result of which I am using to make
decisions in combined expressions.
In some expressions, I would like to inverse the return result of
function.

E.g. function contains(source ,search) will return true if "search"
string is found in source string.
I want to make reverse of this by putting it as:
if ( ! contains(s1,s2) ):
return 1

I found that "!" is not accepted by Python & compile fails with
"invalid syntax".
Corresponding to this Boolean Operator we've "not" in Python.

How can I make "not" as "!"?
"not" is a perfectly valid boolean operator in Python and means just
what "!" means in C. The equivalent binary operator is "~", just like in C.
>>print not True
False
>>print not 1
False
>>print not 0
True
>>print ~1
-2
>>print ~0
-1

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIJFeIldn AQVacBcgRAgOqAJ 44VoYv275VxN0j3 2X3TBo/jx/D2ACgyp2w
grnFynwn5ULYufM TmpOj5WU=
=EKDP
-----END PGP SIGNATURE-----

Jun 27 '08 #2
On May 9, 8:41*am, grbgooglefan <ganeshbo...@gm ail.comwrote:
I am creating functions, the return result of which I am using to make
decisions in combined expressions.
In some expressions, I would like to inverse the return result of
function.

E.g. function contains(source ,search) will return true if "search"
string is found in source string.
I want to make reverse of this by putting it as:
if ( ! contains(s1,s2) ):
* * *return 1

I found that "!" is not accepted by Python & compile fails with
"invalid syntax".
Corresponding to this Boolean Operator we've "not" in Python.

How can I make "not" as "!"?
I have found that not 8, not not 8, and ~8 are all valid. Valid8 is
not.

NameError: name 'Valid8' is not defined, where defined is not defined,
and @Valid8 @Valid8 ...

Late-binding logicals are fine. #Valid8
Jun 27 '08 #3
grbgooglefan a écrit :
I am creating functions, the return result of which I am using to make
decisions in combined expressions.
In some expressions, I would like to inverse the return result of
function.

E.g. function contains(source ,search) will return true if "search"
string is found in source string.
Do you really need a function for this ?

if "foo" in "foobar":
print "do you really really need a function for this ?"

I want to make reverse of this by putting it as:
if ( ! contains(s1,s2) ):
return 1
which is a convoluted way to write:

return s2 not in s1

I found that "!" is not accepted by Python & compile fails with
"invalid syntax".
Corresponding to this Boolean Operator we've "not" in Python.

How can I make "not" as "!"?
Err... How to say... The boolean negation operator in Python is "not".
So the only answer I can provide is : "use 'not' instead of '!'". And
while we're at it : drop those useless parens.

HTH
Jun 27 '08 #4
-----Original Message-----
From: py************* *************** ****@python.org [mailto:python-
li************* ************@py thon.org] On Behalf Of grbgooglefan
Sent: Friday, May 09, 2008 9:41 AM
To: py*********@pyt hon.org
Subject: How to modify meaning of builtin function "not" to "!"?

I am creating functions, the return result of which I am using to make
decisions in combined expressions.
In some expressions, I would like to inverse the return result of
function.

E.g. function contains(source ,search) will return true if "search"
string is found in source string.
I want to make reverse of this by putting it as:
if ( ! contains(s1,s2) ):
return 1

I found that "!" is not accepted by Python & compile fails with
"invalid syntax".
Corresponding to this Boolean Operator we've "not" in Python.

How can I make "not" as "!"?

Serious question: Why would you want to? 'not' is easier to read (and type) than '!'. Mentally, when you see '!' you think 'not'. It's also harder to overlook 'not', especially when compared to '!contains()'. Finally, I imagine that Spanish speaking coders suffer enormous mental anguish when they see a right-side up '!' at the beginning of a sentence.

if ( ! contains(s1,s2) ):
return 1

if ( !contains(s1,s2 ) ):
return 1

if ( not contains(s1,s2) ):
return 1

if ( ¡contains(s1,s2 )):
return 1


*****

The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. GA625
Jun 27 '08 #5

"grbgooglef an" <ga*********@gm ail.comwrote in message
news:fc******** *************** ***********@k10 g2000prm.google groups.com...
|I am creating functions, the return result of which I am using to make
| decisions in combined expressions.
| In some expressions, I would like to inverse the return result of
| function.
|
| E.g. function contains(source ,search) will return true if "search"
| string is found in source string.
| I want to make reverse of this by putting it as:
| if ( ! contains(s1,s2) ):
| return 1
|
| I found that "!" is not accepted by Python & compile fails with
| "invalid syntax".
| Corresponding to this Boolean Operator we've "not" in Python.
|
| How can I make "not" as "!"?

1. Download, edit, and compile Python source code.
Perhaps substituting '!' for 'not' in the grammar file will suffice.
I do not *think* that this would conflict with '!=' digraph.
2. Realize that code for your custom Python will not work anywhere else if
it does contain '!' with that meaning.

Jun 27 '08 #6
Lie
On May 9, 8:41*pm, grbgooglefan <ganeshbo...@gm ail.comwrote:
I am creating functions, the return result of which I am using to make
decisions in combined expressions.
In some expressions, I would like to inverse the return result of
function.

E.g. function contains(source ,search) will return true if "search"
string is found in source string.
I want to make reverse of this by putting it as:
if ( ! contains(s1,s2) ):
* * *return 1

I found that "!" is not accepted by Python & compile fails with
"invalid syntax".
Corresponding to this Boolean Operator we've "not" in Python.

How can I make "not" as "!"?
Are you trying to make Python a C? Realize that when you work with a
language, you play by that language's rule, not by your rule. This
seems like a troll or something.
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1618
by: Pierre Rouleau | last post by:
Hi all, In several occasions, I found myself looking for a function that would take a value and restrict is within a specified set of boundaries. For a 1-dimension value, I could simply write min(max(value,theMin),theMax) to restrict value within the range made of theMin to theMax. It assumes that theMax >= theMin.
0
1232
by: User | last post by:
I am looking for a function that can dial up an ISP, connect and/or log off through a Python script running under windows. I looked in socket, but didn't find anything that looks promising. Any suggestions? If it is just an executable file belonging to windows that I need to run, just tell me what the file is and I'll write a script to run it. Thanks.
2
2973
by: Caspy | last post by:
When add a button to a web form, if the button can CauseValidation, the server emits client side javascript as: <input type="submit" name="Button1" value="Button" onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); " language="javascript" id="Button1" /> What I want to let the emitted javascript like : <input type="submit" name="Button1" value="Button" onclick="if (typeof(Page_ClientValidate) == 'function')
2
1527
by: James Thiele | last post by:
What exceptions (if any) can the python builtin compile() function throw besides SyntaxError?
8
1712
by: Jose Cintron | last post by:
Hello all. Newbie question here... I have a program that needs to do 1 of 2 things 1. declare a global System::String (which I think can't be done, because VS 2005 complains) 2. modify the System::String in one function An example may be easier to understand... The question is how would I get the second option to work???
6
7876
by: Kiran | last post by:
Hi all, What I am trying to do is to pass a pointer to the first element of an array to a function, modify it in that function, and then print out the values of the array (which has been modified by the function) in main. However, I am getting a segmentation fault. Here is the code: (Please note, the size is fixed in this code, but in my code where I am actually going to use this, the size of the array is not known until you get to the...
1
3252
by: lavender | last post by:
What are the meaning and function for BOOL in C programming
2
3153
by: mshahzadali | last post by:
is there any expert who could guide me making a C++ program. I want to convert a Decimal number into a Binary, Octal and a Hexadecimal Number using a C++ Built-in Function(if there exist any).
1
1399
by: DR | last post by:
When a clr has the input type of SqlString it causes nvarchar(4000) to be the parameter type of the function in sql server. how to modify my CLR function to use nvarchar(max) ?
0
9643
marktang
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...
0
10315
Oralloy
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...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6737
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();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
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
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.