Hope u all might have come across the string deprecation thought of in
For example : string.lower(str) needs to be some thing like
Can some one help me out whether such a change in the common python
"string.digits" to be changed. If yes wat would be ur suggestions
Thanks for ur inputs
> Hi All
> Hope u all might have come across the string deprecation thought of in
> Python 3.0.
> For example : string.lower(str) needs to be some thing like
> Can some one help me out whether such a change in the common python
> would require
> "string.digits" to be changed. If yes wat would be ur suggestions
> Thanks for ur inputs
Some of the functions in module string are being deprecated in favor of
new methods on the str type itself. The digits variable of the string
module is just a string of the '0123456789' digits. It's unlikely to
be deprecated since it doesn't make much sense to make it an attribute
of the str type.
Also, to answer another question of yours, observe:
Let me toss the question back at you: Does it make sense to you that
str should have this attribute? Why?
I'm not advocating for or against one thing or another, and I'm
certainly not in a position to influence the future development of
Python (anymore than any of us, that is ) but FWIW, here's my
My "feeling" is that since str is a Type, and not a data store, it
doesn't make much sense to me to tack on a bunch of read-only data
attributes that aren't involved in it's role as a string data type just
to have a slightly more convenient way of accessing them.
There are twelve "constants" defined in the string module. If they
were all attributes of the str type it would, for me, conceptually
"clutter up" my mental model of str, string, and python itself.
I like "from string import digits" well enough, and, as a test of my
mental model, I just used IDLE's "open module" command to find and open
string.py and discovered:
Really, I wouldn't be too badly shocked to discover the above string
"constants" in dir(str), so it's kind of "six of one, a half dozen of
the other". But on the same token, "if it's not broken, don't fix it."
Further, to make these "constants" into attributes of str, someone
would have to modify the str type at the C level to put these strings
"on" it. Since they are str's themselves, it seems to me (having done
only trivial work with the C API of python) that that someone would
have to A) create a "first" str type, B) create these 12 strings using
that first type, C) attach them to the str type to create a "final" str
type. And all this would have to be done at startup, I think, even if
my code didn't use these attributes. It seems messy to me.
So to sum up, IMO, a module (rather than a type) is a good place for
these things, a module with some variable assignments is completely
within my mental model of python (i.e. no special case (of strings
being attributes of their own type (!?))), and no one has to do
anything special to make the current set up work.
By the way, I read your post a few days ago concerning adding similar
data attributes to ints and floats and found it very interesting but
While I would love to have the kind information you mentioned
available, I've never needed it in practice (I've only ever used
sys.maxint maybe a dozen times) and I wouldn't mind accessing it from a
module (perhaps math.. math.infinity, math.epsilon, etc., just like
math.pi and math.e.)
I look forward to hearing your thoughts an the subject. I hope mine
haven't been too silly..
> accessing it from a
> module (perhaps math.. math.infinity, math.epsilon, etc., just like
> math.pi and math.e.)
It too looks acceptable.
> I look forward to hearing your thoughts an the subject.
Thank you, but I am not expert enough on such topics to give you good
comments, so I keep the muzzle shut.
(E-Mail Removed) wrote:
> Simon Forman:
>> accessing it from a
>> module (perhaps math.. math.infinity, math.epsilon, etc., just like
>> math.pi and math.e.)
> It too looks acceptable.
>> I look forward to hearing your thoughts an the subject.
> Thank you, but I am not expert enough on such topics to give you good
> comments, so I keep the muzzle shut.
I've been thinking along this lines as well, but with the more general
question of when should a method or attribute be included in a type or
class and when shouldn't it. I think that's an important question and
having some clear guidelines for that will help me to write better
programs in general.
A few general rules I've found to be mostly true is..
(1) If a class method does not have a reference to 'self' or an
attribute or other method of self. It probably should be a
This is more common than you might think because class's are also used
as containers to hold a collection of functions and/or values. I think
its useful to keep these collections separate from "objects". It keeps
the objects simpler, and the collection of functions and values clearer.
The difficulty is when you mix the two together, that's when you begin
to get a cluttered class that is difficult to understand.
(2) If no method of a class has a reference to an attribute,
then the attribute should probably not be part of the class
On the flip side, the inverse of these rules does not necessarily mean
something should be in the class. But maybe...
(3) If an value is not useful by other class's or functions.
It probably should be an attribute of the class.
These are just guide lines of course, but by keeping them in mind, I do
think it has helped me to abstain from writing cluttered class's.
Maybe there are other guidelines like these that are helpful?