[Patches] [ python-Patches-825313 ] Add additional isxxx functions
to string object.
SourceForge.net
noreply at sourceforge.net
Fri Oct 24 03:34:19 EDT 2003
Patches item #825313, was opened at 2003-10-17 07:47
Message generated for change (Comment added) made by lemburg
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=825313&group_id=5470
Category: Core (C code)
Group: Python 2.4
Status: Open
Resolution: None
>Priority: 1
Submitted By: Eric Huss (ehuss)
Assigned to: Nobody/Anonymous (nobody)
Summary: Add additional isxxx functions to string object.
Initial Comment:
This patch adds the following ctype.h functions to the
string object.
iscntrl
isgraph
isprint
ispunct
isxdigit
These are pretty standard C functions...I'm not sure
why they were left out.
It also deletes a lot of duplicated code.
This patch might not be 100% useful because it does
not have the unicode equivalents. Thoughts?
----------------------------------------------------------------------
>Comment By: M.-A. Lemburg (lemburg)
Date: 2003-10-24 09:34
Message:
Logged In: YES
user_id=38388
-1 from here. You can have the same using a regular expression
character group built using the unicodedata(base) or just
using a static mapping for 8-bit chars.
There are too few use cases for these methods that it would
make sense adding extra logic and static data to make the
mapping fast enough.
Brett, feel free to close this request.
----------------------------------------------------------------------
Comment By: Brett Cannon (bcannon)
Date: 2003-10-24 02:34
Message:
Logged In: YES
user_id=357491
You don't need to understand my comment because I goofed. For
some reason I remember reading ``help(str.isdigit)`` and it
saying it only worked for a single character.
I still don't find these that useful. isgraph seems especially
useless since you could easily just strip the whitespace out and
then call isprint on it.
For the argument of keeping the names with C, that is not valid.
This is being introduced into Python for the first time and thus
should have a proper name. There is not enough of a widespread
connection to C in terms of these functions to have to worry about
keeping the name the same.
Regardless of all of this I am still -1 on all of the methods.
----------------------------------------------------------------------
Comment By: Eric Huss (ehuss)
Date: 2003-10-23 20:11
Message:
Logged In: YES
user_id=393416
isprint is useful to make sure there are "safe" characters in a
string. In a tty-based application, and you have potentially
hostile text to display to the user, you want to make sure
that no terminal control characters are sent.
isgraph is exactly the same as isprint, except it does not
include the space character.
I do not understand Brett's comment about isxdigit. I would
avoid renaming it since the naming convention already follows
the C functions. And it is not the same as isalnum and
isalpha...which is the same as isdigit (which already exists).
isxdigit tests for a hexadecimal character (0-9 a-f A-F).
I think it would be mildly useful. I can follow up with a patch
for documentation and unit tests. As for Unicode support,
unforutnately I do not know where to begin to update
makeunicodedata.py.
----------------------------------------------------------------------
Comment By: Martin v. Löwis (loewis)
Date: 2003-10-18 11:58
Message:
Logged In: YES
user_id=21627
The patch is incomplete, as it comes without documentation
and test cases. Eric, I would normally request these at this
point, but I'm also with Brett that wrapping these functions
might be useless.
What is the rationale for including them?
----------------------------------------------------------------------
Comment By: Brett Cannon (bcannon)
Date: 2003-10-17 21:53
Message:
Logged In: YES
user_id=357491
I don't really see a good use for any of these. Chances that most
people are going to need most of these is very minor (heck, I
don't even know what isgraph would test for).
isxdigit might be slightly helpful if you renamed it isnum, but you
can fake that already with ``x.isalnum() and not x.isalpha()``.
But in general I am -1 on these. str has enough methods as it is.
----------------------------------------------------------------------
Comment By: Andrew Gaul (gaul)
Date: 2003-10-17 21:26
Message:
Logged In: YES
user_id=139865
I like shedding ~80 lines with is_helper, especially if you
add inline. Otherwise, function call overhead might be
incurred for every call to C isfoo() instead of inlining the
comparison. I dislike increasing the distinction between
ASCII and Unicode strings, although Unicode strings already
have isdecimal and isnumeric methods which ASCII strings
lack. I would at least add iscntrl, ispunct, and isxdigit
to Unicode strings if they are added to ASCII strings.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=825313&group_id=5470
More information about the Patches
mailing list