niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » python
Depricated String Functions in Python
Post new topic   Reply to topic Page 1 of 1 [15 Posts] View previous topic :: View next topic
Author Message
Duncan Booth
*nix forums Guru


Joined: 11 Mar 2005
Posts: 422

PostPosted: Fri Jul 21, 2006 7:41 am    Post subject: Re: Depricated String Functions in Python Reply with quote

Sybren Stuvel wrote:

Quote:
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.
Back to top
Steve Holden
*nix forums Guru


Joined: 22 Feb 2005
Posts: 1255

PostPosted: Thu Jul 20, 2006 6:04 pm    Post subject: Re: Depricated String Functions in Python Reply with quote

Donn Cave wrote:
[...]
Quote:

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
Back to top
Sybren Stuvel
*nix forums Guru


Joined: 22 Feb 2005
Posts: 550

PostPosted: Thu Jul 20, 2006 4:37 pm    Post subject: Re: Depricated String Functions in Python Reply with quote

Donn Cave enlightened us with:
Quote:
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)

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Back to top
Donn Cave
*nix forums Guru Wannabe


Joined: 20 Feb 2005
Posts: 172

PostPosted: Thu Jul 20, 2006 4:31 pm    Post subject: Re: Depricated String Functions in Python Reply with quote

In article <mailman.8368.1153402047.27775.python-list@python.org>,
Steve Holden <steve@holdenweb.com> wrote:

Quote:
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, donn@u.washington.edu
Back to top
riquito@gmail.com
*nix forums beginner


Joined: 14 Jun 2006
Posts: 5

PostPosted: Thu Jul 20, 2006 2:02 pm    Post subject: Re: Depricated String Functions in Python Reply with quote

Steve Holden ha scritto:

Quote:
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
Quote:
def doit(what):
.... def func(x):

.... return getattr(x,what)()
.... return func
....
Quote:
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
Back to top
Duncan Booth
*nix forums Guru


Joined: 11 Mar 2005
Posts: 422

PostPosted: Thu Jul 20, 2006 1:36 pm    Post subject: Re: Depricated String Functions in Python Reply with quote

Anoop wrote:

Quote:
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 ]
Back to top
Simon Forman
*nix forums addict


Joined: 22 Jun 2006
Posts: 83

PostPosted: Thu Jul 20, 2006 1:30 pm    Post subject: Re: Depricated String Functions in Python Reply with quote

Anoop wrote:
Quote:
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
Back to top
Steve Holden
*nix forums Guru


Joined: 22 Feb 2005
Posts: 1255

PostPosted: Thu Jul 20, 2006 1:26 pm    Post subject: Re: Depricated String Functions in Python Reply with quote

Anoop wrote:
Quote:
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):

Quote:
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
Back to top
Anoop
*nix forums beginner


Joined: 20 Jul 2006
Posts: 5

PostPosted: Thu Jul 20, 2006 1:15 pm    Post subject: Re: Depricated String Functions in Python Reply with quote

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:
Quote:
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
Back to top
Sybren Stuvel
*nix forums Guru


Joined: 22 Feb 2005
Posts: 550

PostPosted: Thu Jul 20, 2006 12:41 pm    Post subject: Re: Depricated String Functions in Python Reply with quote

Steve Holden enlightened us with:
Quote:
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.

I don't think it'll help much. If someone can program a computer,
he/she certainly should be able to look up a word in a dictionary.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Back to top
Steve Holden
*nix forums Guru


Joined: 22 Feb 2005
Posts: 1255

PostPosted: Thu Jul 20, 2006 8:21 am    Post subject: Re: Depricated String Functions in Python Reply with quote

John Machin wrote:
Quote:
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 Smile


Quote:
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
Back to top
John Machin
*nix forums Guru


Joined: 19 Feb 2005
Posts: 608

PostPosted: Thu Jul 20, 2006 7:55 am    Post subject: Re: Depricated String Functions in Python Reply with quote

On 20/07/2006 5:18 PM, Steve Holden wrote:
Quote:
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
Back to top
Steve Holden
*nix forums Guru


Joined: 22 Feb 2005
Posts: 1255

PostPosted: Thu Jul 20, 2006 7:18 am    Post subject: Re: Depricated String Functions in Python Reply with quote

Anoop wrote:
Quote:
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
Back to top
Stefan Behnel
*nix forums addict


Joined: 18 Apr 2005
Posts: 81

PostPosted: Thu Jul 20, 2006 6:38 am    Post subject: Re: Depricated String Functions in Python Reply with quote

Anoop wrote:
Quote:
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
Back to top
Anoop
*nix forums beginner


Joined: 20 Jul 2006
Posts: 5

PostPosted: Thu Jul 20, 2006 6:26 am    Post subject: Depricated String Functions in Python Reply with quote

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
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [15 Posts] View previous topic :: View next topic
The time now is Thu Dec 04, 2008 2:14 am | All times are GMT
navigation Forum index » Programming » python
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts FAQ 4.32 How do I strip blank space from the beginning/en... PerlFAQ Server Perl 0 Fri Jul 21, 2006 1:03 pm
No new posts Python proficiency test Kent Johnson python 0 Fri Jul 21, 2006 10:47 am
No new posts FAQ 4.34 How do I extract selected columns from a string? PerlFAQ Server Perl 0 Fri Jul 21, 2006 7:03 am
No new posts Since there was talk of if-then-else not being allowed in... Casey Hawthorne python 5 Fri Jul 21, 2006 3:41 am
No new posts print all permutations of string anurag C 10 Thu Jul 20, 2006 5:57 pm

Per Insurance | Get Rid of Debt | Gas Suppliers | Debt Help | Credit Card
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 1.7520s ][ Queries: 20 (1.5739s) ][ GZIP on - Debug on ]