471,354 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

qa

I'm trying to get a space in between these two strings but it's ignoring
the space in between when it prints.
>>string.capwords (string.join([s1 + " " + s2])) * 3
'Spam Ni!Spam Ni!Spam Ni!'
>>>
Sep 17 '07 #1
1 1148
On Sep 18, 7:15 am, Shawn Minisall <trekker...@gmail.comwrote:
I'm trying to get a space in between these two strings but it's ignoring
the space in between when it prints.
>>string.capwords (string.join([s1 + " " + s2])) * 3
'Spam Ni!Spam Ni!Spam Ni!'
>>>
-1. "qa" as a subject heading scarcely invites potential readers to
bother opening up your posting ...
0. Which 2 strings? You have got a space between 'spam' and 'ni'.
1. string.join([ONLY_ONE_element]) is a big fat no-operation.
2. It's ignoring what space when it prints?
3. Break your expression down into simple steps, so that you can see
where you are going wrong, like this:
>>import string
s1 = 'spam'
s2 = 'ni!'
s3 = s1 + " " + s2
s3
'spam ni!'
>>list1 = [s3]
list1
['spam ni!']
>>s4 = string.join(list1)
s4
'spam ni!'
>>s5 = string.capwords(s4)
s5
'Spam Ni!'
>>s6 = s5 * 3
s6
'Spam Ni!Spam Ni!Spam Ni!'
>>>
Now: which part(s) of the above are not doing what you expected, and
what did you expect, and what is the basis for your expectation?

4. Almost all of the string module is deprecated -- instead you should
be using methods of string objects. Are you using an old book or
tutorial? If so, throw it away; it's well out of date.

5. capwords breaks the string into words (like the following) which is
a bit silly on a string that you've just laboriously constructed.
>>def capwords(s):
.... return " ".join(w.capitalize() for w in s.split())
....
>>capwords('foo bar zot')
'Foo Bar Zot'
>>>
6. What are you actually trying to achieve?
Sep 17 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by William C. White | last post: by
2 posts views Thread by Albert Ahtenberg | last post: by
3 posts views Thread by James | last post: by
reply views Thread by Ollivier Robert | last post: by
1 post views Thread by Richard Galli | last post: by
4 posts views Thread by Albert Ahtenberg | last post: by
1 post views Thread by inderjit S Gabrie | last post: by
2 posts views Thread by Jack | last post: by
3 posts views Thread by Sandwick | last post: by

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.