> > Why is the strip( ) method returning something that is not a mystr
> > instance? I would expect all methods operating on a string instance
> > and returning another string instance to correctly operate on a mystr
> > instance and return a mystr instance.
>
> Why would you expect that?
> Would y
On Apr 16, 3:28 am, "Daniel Nogradi" <[EMAIL PROTECTED]> wrote:
> I would expect all methods operating on a string instance
> and returning another string instance
Ok, then this:
class A(object):
def __init__(self, s):
self.s = s
def strip(self):
return self.s
class mystr
"Daniel Nogradi" <[EMAIL PROTECTED]> wrote:
> Why is the strip( ) method returning something that is not a mystr
> instance? I would expect all methods operating on a string instance
> and returning another string instance to correctly operate on a mystr
> instance and return a mystr instance.
Wh
On Apr 16, 3:28 am, "Daniel Nogradi" <[EMAIL PROTECTED]> wrote:
> I am probably misunderstanding some basic issue here but this
> behaviour is not what I would expect:
>
> Python 2.4 (#1, Mar 22 2005, 21:42:42)
> [GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2
> Type "help", "copyright", "
anthonyberet wrote:
> For example if I wanted to replace the 4th character in 'foobar' (the
> b)with the contents of another string, newchar, what would be the
> easiest way?
Depends on how your input is specified. If you know it is the b you
want to replace, you write
>>> text="foobar"
>>> t
Brian Beck wrote:
> anthonyberet wrote:
>>I know this touches on immutability etc, but I can't find string methods
>>to return the first 3 characters, and then the last 2 characters, which
>>I could concatenate with newchar to make a new string.
>
> As tiissa said, you want slicing:
>
> py> s = "
anthonyberet wrote:
> I know this touches on immutability etc, but I can't find string methods
> to return the first 3 characters, and then the last 2 characters, which
> I could concatenate with newchar to make a new string.
As tiissa said, you want slicing:
py> s = "foobar"
py> s[:3]
'foo'
py>
anthonyberet wrote:
> I know this touches on immutability etc, but I can't find string methods
> to return the first 3 characters, and then the last 2 characters, which
> I could concatenate with newchar to make a new string.
>
> I know the string methods are there, but can't find it in any docs
On Sun, 27 Feb 2005 18:12:17 -0700, rumours say that Steven Bethard
<[EMAIL PROTECTED]> might have written:
[snip Nick Coghlan's list comprehension]
[STeVe]
>On the other hand, filter doesn't do the same thing:
>
>py> s = u'The Beatles - help - 03 - Ticket to ride'
>py> filter(str.isalpha, s)
>Tr
On Sun, 27 Feb 2005 18:12:17 -0700, rumours say that Steven Bethard
<[EMAIL PROTECTED]> might have written:
[snip Nick Coghlan's list comprehension]
[STeVe]
>On the other hand, filter doesn't do the same thing:
>
>py> s = u'The Beatles - help - 03 - Ticket to ride'
>py> filter(str.isalpha, s)
>Tr
Nick Coghlan wrote:
Jimmy Retzlaff wrote:
The approach you are considering may be easier than you think:
filter(str.isalpha, 'The Beatles - help - 03 - Ticket to ride')
'TheBeatleshelpTickettoride'
Hmm, I think this is a case where filter is significantly clearer than
the equivalent list comprehen
Jimmy Retzlaff wrote:
Anthonyberet wrote:
Is there a string mething to return only the alpha characters of a
string?
eg 'The Beatles - help - 03 - Ticket to ride', would be
'TheBeatlesTickettoride'
If not then how best to approach this?
I have some complicated plan to cut the string into individual
Jimmy Retzlaff wrote:
The approach you are considering may be easier than you think:
filter(str.isalpha, 'The Beatles - help - 03 - Ticket to ride')
'TheBeatleshelpTickettoride'
Hmm, I think this is a case where filter is significantly clearer than the
equivalent list comprehension:
Py> "".join(
"anthonyberet" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Is there a string mething to return only the alpha characters of a
> string?
> eg 'The Beatles - help - 03 - Ticket to ride', would be
> 'TheBeatlesTickettoride'
I believe you can do this with string.translate (string
Anthonyberet wrote:
> Is there a string mething to return only the alpha characters of a
string?
> eg 'The Beatles - help - 03 - Ticket to ride', would be
> 'TheBeatlesTickettoride'
>
> If not then how best to approach this?
> I have some complicated plan to cut the string into individual
> charac
anthonyberet wrote:
Is there a string mething to return only the alpha characters of a string?
eg 'The Beatles - help - 03 - Ticket to ride', would be
'TheBeatlesTickettoride'
If not then how best to approach this?
I have some complicated plan to cut the string into individual
characters and the
anthonyberet wrote:
Is there a string mething [method] to return only the alpha characters of a string?
eg 'The Beatles - help - 03 - Ticket to ride', would be
'TheBeatlesTickettoride'
erm, no it wouldn't, it would be 'TheBeatleshelpTickettoride', but you
get me, I am sure.
If not then how bes
17 matches
Mail list logo