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

string goes away

Hi:

If I am getting the docs etc. correctly, the string-module is depricated
and is supposed to be removed with the release of Python 3.0.
I still use the module a lot and there are situations in which I don't
know what to do without it. Maybe you can give me some help.

I loved to use
string.join(list_of_str, sep) instead of sep.join(list_of_str)
I think the former is much more telling what is happening than the
latter. However, I will get used to it.

But what about this: upper_list = map(string.upper, list_of_str)


What am I supposed to do instead?

I am sure there has been lots of discussion on whether or not to remove
the string module. Maybe you can just direct me to the right place.

Thanks for help!
Andreas

Jul 18 '05 #1
8 4020
Hey Andreas,
I loved to use
>>> string.join(list_of_str, sep) instead of >>> sep.join(list_of_str)
I think the former is much more telling what is happening than the
latter. However, I will get used to it.
I find that binding a name to the separator makes it more readable
(YMMV):
list_of_str = ['a','b','c']
comma = ','
comma.join(list_of_str) 'a,b,c'
But what about this:
>>> upper_list = map(string.upper, list_of_str)

upper_list = [s.upper() for s in list_of_str]
upper_list

['A', 'B', 'C']

Hope this helps.

-alex23

Jul 18 '05 #2
Andreas Beyer wrote:
I loved to use
string.join(list_of_str, sep) instead of sep.join(list_of_str)


I think the former is much more telling what is happening than the
latter. However, I will get used to it.


No need to get used to it. Just reverse the order of the arguments and use:

str.join(sep, list_of_str)

Alternatively it can be clearer if you bind a name to the bound method:

joinLines = '\n'.join
joinWords = ' '.join

lines = joinLines(somelines)
words = joinWords(somewords)
Jul 18 '05 #3
Duncan Booth <du**********@invalid.invalid> writes:
[...]
str.join(sep, list_of_str)

[...]

Doesn't work with unicode, IIRC.

John
Jul 18 '05 #4
Andreas Beyer wrote:
If I am getting the docs etc. correctly, the string-module is depricated
and is supposed to be removed with the release of Python 3.0.
I still use the module a lot and there are situations in which I don't
know what to do without it. Maybe you can give me some help.


Out of curiosity: when thinking about Python 3.0, what is the timespan
in which you expect that to appear? Before 2010? After 2010? After 2020?

Regards,
Martin
Jul 18 '05 #5
"Martin v. Löwis" <ma****@v.loewis.de> writes:
Out of curiosity: when thinking about Python 3.0, what is the timespan
in which you expect that to appear? Before 2010? After 2010? After 2020?


I'm not terribly worried about Python 3.0 incompatibilities, whenever
those are. There are already three incompatible Python versions
(CPython, Jython, IronPython) with PyPy coming right along. If any of
those newer ones take off in popularity, there's going to be much more
interoperability hassle than 3.0 will cause.
Jul 18 '05 #6
John J. Lee wrote:
Duncan Booth <du**********@invalid.invalid> writes:
[...]
str.join(sep, list_of_str)

[...]

Doesn't work with unicode, IIRC.

u" ".join(["What's", "the", "problem?"])

u"What's the problem?"

Jul 18 '05 #7
Dan Bishop wrote:
John J. Lee wrote:
Doesn't work with unicode, IIRC.

u" ".join(["What's", "the", "problem?"])
u"What's the problem?"


str.join(x, y) isn't quite a drop-in replacement for
string.join(y, x), since it's not polymorphic on the
joining string:
str.join(u" ", ["a", "b"]) Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: descriptor 'join' requires a 'str' object but received a 'unicode'

The strings being joined can be unicode, though:
str.join(" ", [u"a", u"b"])

u'a b'

So it's probably not a serious problem, since in most
cases you'll know whether the joining string is unicode
or not when you write the code. If not, you'll just
have to do it the "new" way.

--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
Jul 18 '05 #8
John J. Lee wrote:
Duncan Booth <du**********@invalid.invalid> writes:
[...]
str.join(sep, list_of_str)

[...]

Doesn't work with unicode, IIRC.

str.join won't work if sep is unicode, but generally you know what type the
separator is and str.join will quite happily join a list of strings where
one or more is unicode and return a unicode result.

If you know the separator is unicode then use unicode.join instead.
Jul 18 '05 #9

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

Similar topics

2
by: John F Dutcher | last post by:
There must be a 'fundamental' reason why 'string' functions are reported as 'not found' even though the 'import string' statement is present. If the script has user-defined functions at its...
3
by: Scott Brady Drummonds | last post by:
Hi, all, I've a fairly small piece of code that is causing me problems. I'm using std::string and am building a string of several dozen characters using several of std::string's functions: a...
2
by: s88 | last post by:
Howdy everyone: for example, the psudo code is string ABC; string DEF; string cat = ABC+"__"+DEF; what is the most popular operations in C to make the above psudo code? for example, I'll do it...
16
by: jcf | last post by:
I need to do the following: Our application builds information from a string that is stored in a buffer that can be any of the following formats: ABCD0102, ABCDEF0102, AB*CD*01*02, AB*CDEF*01*02....
19
by: Paul | last post by:
hi, there, for example, char *mystr="##this is##a examp#le"; I want to replace all the "##" in mystr with "****". How can I do this? I checked all the string functions in C, but did not...
20
by: Opettaja | last post by:
I am new to c# and I am currently trying to make a program to retrieve Battlefield 2 game stats from the gamespy servers. I have got it so I can retrieve the data but I do not know how to cut up...
10
by: dba123 | last post by:
Why am I getting this error for Budget? Error: An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code Additional information: String was not...
7
by: carterweb | last post by:
This is how I do it now. 1. Determine the dimensions of the rectangle. 2. Set a my font size to a fixed maximum size. 3. Apply the font my string and measure the string using the graphics...
19
by: VK | last post by:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ b495b4898808fde0> is more than one month old - this may pose problem for posting over some news servers. This is why I'm...
1
by: cakeathon | last post by:
I'm working my way through the accelerated C++ book, and exercise 10-5, & 10-6 have me stuck I have the follwing class in a header file: class String_list { public: String_list(); void...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...

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.