473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

str.isspace()

Are you using the str.isspace() method? I don't use it, so if most
people don't uses it, then it may be removed from Py 3.0.

I usually need to know if a string contains some non-spaces (not space
class chars). To do it I use something like:

if aline.strip(): ...

If you really need str.isspace() you may use (but so far I have never
had to do this):

if txt and not txt.strip(): ...

Bye,
bearophile

Sep 3 '06 #1
2 4519
be************@lycos.com wrote:
Are you using the str.isspace() method? I don't use it, so if most
people don't uses it, then it may be removed from Py 3.0.

I usually need to know if a string contains some non-spaces (not space
class chars). To do it I use something like:

if aline.strip(): ...

If you really need str.isspace() you may use (but so far I have never
had to do this):

if txt and not txt.strip(): ...

Bye,
bearophile
A quick check of code in my homedir showed that I've used it about 60
times (that's just in my own code, not work related code.)

In favor of removing it:
* TOOWTDI

In favor of keeping it:

* isspace() returns a Boolean, strip() returns a (newly-allocated)
string that's then just thrown away.

* it's more obvious, "is space?" is exactly what I'm thinking when I
reach for isspace(), it's never occurred to me to use strip() for this
task. Compare:
if offset >= len(line) or line[offset].isspace():
if offset >= len(line) or line[offset].strip():

* it's "symetrical" with the rest of the isfoo() string methods.
IMHO, it would be odd if it wasn't there.

My $0.02
Peace,
~Simon

Sep 3 '06 #2
Jean-Paul Calderone wrote:
On 3 Sep 2006 09:20:49 -0700, be************@lycos.com wrote:
Are you using the str.isspace() method? I don't use it, so if most
people don't uses it, then it may be removed from Py 3.0.

I usually need to know if a string contains some non-spaces (not space
class chars). To do it I use something like:

if aline.strip(): ...

If you really need str.isspace() you may use (but so far I have never
had to do this):

if txt and not txt.strip(): ...

Bye,
bearophile

Great idea.

By the way, are you using division? I don't use it, so if most people
don't use it, then it may be removed from Py 3.0.

If you really need division, you may use:

x * (y ** -1)

Bye,
Jean-Paul
LOL... well said.

Sep 3 '06 #3

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

Similar topics

35
by: Durgesh Sharma | last post by:
I want to use strrchar(source_string,last_char ) function from string.h header file,to find out the last occurrence of the NON SPACE Alphanumeric Character. Then i will put a NULL CHAR after...
5
by: Durgesh Sharma | last post by:
Are there no genric Macros in c to represent Integers,Characters,...or other data types ? I want to pass that MACRO (representing an alpha numeric Character)to that strrchar() function,to get the...
68
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
2
by: Adrian | last post by:
Hi All, Is there anyway to change what isspace thinks is a space character. I am parsing some log files and it would be nice to just read a field as what ever is between quotes or between 's ie...
31
by: rkk | last post by:
Hi, I've written a small trim function to trim away the whitespaces in a given string. It works well with solaris forte cc compiler, but on mingw/cygwin gcc it isn't. Here is the code: char...
8
by: Count Dracula | last post by:
The following three functions check whether a given string represents a valid number. They require that the entire string represent a number, unlike strtod which accepts strings like "99rQF" and...
7
by: Army1987 | last post by:
Does the Standard forbid isspace(0) from returning 1 in any locale? Is it possible that in some locales the loop for (cursor = nptr; isspace((unsigned char)*cursor); cursor++) continue; slips off...
7
by: Peter Kleiweg | last post by:
Is this a bug or a feature? Python 2.4.4 (#1, Oct 19 2006, 11:55:22) on linux2 'a b c\xa0d e' u'a b c\xa0d e'
16
by: lovecreatesbea... | last post by:
It takes mu so time to finish this C source code line count function. What do you think about it? / ******************************************************************************* * Function ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...
0
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...

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.