473,386 Members | 1,694 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,386 software developers and data experts.

Depricated String Functions in Python

Hi All

Can any one help me out with the various depricated string functions
that is followed in Python.

For example how will be string.lower depricated.

As far as string.lower('PYTHON') is concerned it is depricated as
'PYTHON'.lower(). Both of them would return an output : >>python

Thanks for your inputs

Regards

Anoop

Jul 20 '06 #1
12 1778
Anoop wrote:
Can any one help me out with the various depricated string functions
that is followed in Python.

For example how will be string.lower depricated.

As far as string.lower('PYTHON') is concerned it is depricated as
'PYTHON'.lower(). Both of them would return an output : >>python
I don't quite see the question in your post, but, yes, the module level
functions of the "string" module are deprecated in favour of the methods of
the str and unicode objects.

Stefan
Jul 20 '06 #2
Anoop wrote:
Hi All

Can any one help me out with the various depricated string functions
that is followed in Python.

For example how will be string.lower depricated.

As far as string.lower('PYTHON') is concerned it is depricated as
'PYTHON'.lower(). Both of them would return an output : >>python

Thanks for your inputs
I wonder if this isn't just an English problem: the fact that the
functions of the string module is depracated just means that you are
encouraged to use the string objects' methods instead, as the string
module is likely to be removed at some time in the future.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Jul 20 '06 #3
On 20/07/2006 5:18 PM, Steve Holden wrote:
Anoop wrote:
>Hi All

Can any one help me out with the various depricated string functions
that is followed in Python.

For example how will be string.lower depricated.

As far as string.lower('PYTHON') is concerned it is depricated as
'PYTHON'.lower(). Both of them would return an output : >>python

Thanks for your inputs
I wonder if this isn't just an English problem: the fact that the
functions of the string module is depracated
"depracated"? "functions ... is"? Yup, sure looks like an English
problem to me :-)

Perhaps the docs should use simpler words like "outdated" or "not
preferred" or such-like instead of "depr*e*cated".

Cheers,
John
Jul 20 '06 #4
John Machin wrote:
On 20/07/2006 5:18 PM, Steve Holden wrote:
>>Anoop wrote:
>>>Hi All

Can any one help me out with the various depricated string functions
that is followed in Python.

For example how will be string.lower depricated.

As far as string.lower('PYTHON') is concerned it is depricated as
'PYTHON'.lower(). Both of them would return an output : >>python

Thanks for your inputs

I wonder if this isn't just an English problem: the fact that the
functions of the string module is depracated


"depracated"? "functions ... is"? Yup, sure looks like an English
problem to me :-)
Nobody likes a smartarse :-)
Perhaps the docs should use simpler words like "outdated" or "not
preferred" or such-like instead of "depr*e*cated".
That probably wouldn't be a bad idea. Please note, however, that even if
the documentation spelled everything correctly I would doubtless
continue to mangle the spellings through typos.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Jul 20 '06 #5
Thanks Stefen

let me be more specific how would i have to write the following
function in the deprecated format

map(string.lower,list)

Thanks Anoop
Stefan Behnel wrote:
Anoop wrote:
Can any one help me out with the various depricated string functions
that is followed in Python.

For example how will be string.lower depricated.

As far as string.lower('PYTHON') is concerned it is depricated as
'PYTHON'.lower(). Both of them would return an output : >>python

I don't quite see the question in your post, but, yes, the module level
functions of the "string" module are deprecated in favour of the methods of
the str and unicode objects.

Stefan
Jul 20 '06 #6
Anoop wrote:
Thanks Stefen

let me be more specific how would i have to write the following
function in the deprecated format

map(string.lower,list)
To avoid the deprecated usage you would use the unbound method of the
str type (that's the type of all strings):
>>lst = ['Steve', 'Holden']
map(str.lower, lst)
['steve', 'holden']
>>>
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Jul 20 '06 #7
Anoop wrote:
Thanks Stefen

let me be more specific how would i have to write the following
function in the deprecated format

map(string.lower,list)

Thanks Anoop
Ah. This is easy enough:

lower_list = [s.lower() for s in str_list]

Or, if you really like map() (or really don't like list comprehensions
;P ) you could use this:

lower_list = map(lambda s : s.lower(), str_list)
Hope this helps,
~Simon

Jul 20 '06 #8
Anoop wrote:
let me be more specific how would i have to write the following
function in the deprecated format

map(string.lower,list)
What you just wrote is the deprecated format.

There are plenty of ways to write it in an undeprecated format. The
simplest is probably:

[ s.lower() for s in list ]

Jul 20 '06 #9

Steve Holden ha scritto:
Anoop wrote:
Thanks Stefen

let me be more specific how would i have to write the following
function in the deprecated format

map(string.lower,list)
To avoid the deprecated usage you would use the unbound method of the
str type (that's the type of all strings):
>>lst = ['Steve', 'Holden']
>>map(str.lower, lst)
['steve', 'holden']
>>>
This isn't exactly equal to use string.lower, because this work with
just encoded strings, when string.lower works with unicode too.
I'm used to have a "lower" func like this one
def lower(x): return x.lower()
to use in map. Of course it's a problem when you need many different
methods.

A solution could be something like this
>>def doit(what):
.... def func(x):
.... return getattr(x,what)()
.... return func
....
>>map(doit('lower'),['aBcD',u'\xc0'])
['abcd', u'\xe0']
>>map(doit('upper'),['aBcD',u'\xc0'])
['ABCD', u'\xc0']

The best is to use in advance just unicode or encoded strings in your
program, but this is not always possible :-/

Riccardo Galli

Jul 20 '06 #10
In article <ma***************************************@python. org>,
Steve Holden <st***@holdenweb.comwrote:
Anoop wrote:
Thanks Stefen

let me be more specific how would i have to write the following
function in the deprecated format

map(string.lower,list)
To avoid the deprecated usage you would use the unbound method of the
str type (that's the type of all strings):
>>lst = ['Steve', 'Holden']
>>map(str.lower, lst)
['steve', 'holden']
Oh, excellent - the string module is dead, long live
the string module! I can replace string.join with
str.join, and never have to defile my code with that
' '.join(x) abomination.
Donn Cave, do**@u.washington.edu
Jul 20 '06 #11
Donn Cave wrote:
[...]
>
Oh, excellent - the string module is dead, long live
the string module! I can replace string.join with
str.join, and never have to defile my code with that
' '.join(x) abomination.
>>lst = ['Steve', 'Holden']
str.join(' ', lst)
'Steve Holden'
>>>
Just so long as you don't complain about the arguments being in the
wrong order ...

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Jul 20 '06 #12
Sybren Stuvel wrote:
Donn Cave enlightened us with:
>Oh, excellent - the string module is dead, long live the string
module! I can replace string.join with str.join, and never have to
defile my code with that ' '.join(x) abomination.

It's not an abomination. It's a very clear way of telling those two
apart:

' '.join(x)
u' '.join(x)
I don't understand that comment. Are you saying that str.join vs
unicode.join isn't a clear distinction?

I like using str.join/unicode.join myself, but one advantage of using
separator.join directly is that you can save the bound method:

joinlines = '\n'.join
joinwords = ' '.join

you can't do that by calling the method on the type.
Jul 21 '06 #13

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

Similar topics

18
by: jblazi | last post by:
I should like to search certain characters in a string and when they are found, I want to replace other characters in other strings that are at the same position (for a very simply mastermind game)...
12
by: Kamilche | last post by:
I was looking for a way to speed up detecting invalid characters in my TCP string, and thought of yet another use for the translate function! If you were to 'translate out' the bad characters, and...
11
by: Carlos Ribeiro | last post by:
Hi all, While writing a small program to help other poster at c.l.py, I found a small inconsistency between the handling of keyword parameters of string.split() and the split() method of...
3
by: Hitesh | last post by:
Hi, In python doc -- 4.1.4 Deprecated string functions -- I read that "The following list of functions are also defined as methods of string and Unicode objects; see ``String Methods'' (section...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.