Re: may be a bug in string.rstrip

2007-11-23 Thread Scott SA
On 11/23/07, Bruno Desthuilliers ([EMAIL PROTECTED]) wrote: >> The better option, IMO, is probably to use regex. > >You forgot at least the simplest solution: > >import os.path >os.path.splitext('132.ext')[0] Yes, I did miss that one... and while I was typing there was a nagging feeling I was m

Re: may be a bug in string.rstrip

2007-11-23 Thread Bruno Desthuilliers
Scott SA a écrit : > On 11/23/07, kyo guan ([EMAIL PROTECTED]) wrote: > >> Please look at this code: >> > 'exe.torrent'.rstrip('.torrent') >> 'ex' <- it should be 'exe', why? >> >> but this is a right answer: >> > '120.exe'.rstrip('.exe') >> '120' <

Re: may be a bug in string.rstrip

2007-11-23 Thread Sion Arrowsmith
Scott SA <[EMAIL PROTECTED]> wrote: >>>> string.replace('120.exe','.exe','') >'120' Don't use string.replace(), use the replace method of strings: >>> '120.exe'.replace('.exe', '') '120' >... but it has a side-effect of mid-string replacements: > >>>> string.replace('123.exe.more','.

Re: may be a bug in string.rstrip

2007-11-23 Thread Ant
On Nov 23, 4:09 am, "kyo guan" <[EMAIL PROTECTED]> wrote: ... > >>> '120.exe'.rstrip('.exe') Another approach since you seem to be working with filenames is using the os.path module: >>> import os.path as path >>> s = "test.torrent" >>> t = "test.exe" >>> u = "test" >>> path.splitext(s)[0] 'test'

Re: may be a bug in string.rstrip

2007-11-23 Thread Peter Otten
Scott SA wrote: > There are a lot of cool things you can do with regex, one of them in > relation to your needs, is the ability to replace substrings: > > >>> import re > >>> reg = re.compile('(.exe)$') # the $ means end of line > >>> reg.sub('','123.exe') > '123' Unfortunately t

Re: may be a bug in string.rstrip

2007-11-22 Thread Scott SA
On 11/23/07, kyo guan ([EMAIL PROTECTED]) wrote: > Please look at this code: > 'exe.torrent'.rstrip('.torrent') >'ex' <- it should be 'exe', why? > >but this is a right answer: > '120.exe'.rstrip('.exe') >'120' <-- this is a right value. > > the

Re: may be a bug in string.rstrip

2007-11-22 Thread michael poeltl
hi, what about this >>> 'exe.torrent'.split('.')[0] 'exe' >>> 'exe.torrent'.rstrip('toren').rstrip('.') 'exe' >>> that's what you need, isn't it? On Friday 23 November 2007 05:09:50 am kyo guan wrote: > Hi : > > Please look at this code: > >>> 'exe.torrent'.rstrip('.torrent') > > 'ex'

Re: may be a bug in string.rstrip

2007-11-22 Thread rzed
"kyo guan" <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > Hi : > > Please look at this code: > 'exe.torrent'.rstrip('.torrent') > 'ex' <- it should be 'exe', why? It really shouldn't be. > > but this is a right answer: > '120.exe'.rstrip('.exe'

Re: may be a bug in string.rstrip

2007-11-22 Thread Tyler Reguly
Wow... took someone else to point this out to me.. Kinda feel like an idiot for responding :) rstrip doesn't take a string... it removes all the chars that you list individually... that's why the e was removed... there's an e in .torrent but it hit the x which it didn't match on, so it stopped...

Re: may be a bug in string.rstrip

2007-11-22 Thread Tyler Reguly
Interesting... I tried this on three machines Windows/Python 2.4.3, FC4/Python 2.4.3, Ubuntu/Python 2.5.1 and I saw the same thing for each... It's apparently not a three character issue but rather related to specific characters (e, n, o, r, t). A further test revealed that this affects one additio

may be a bug in string.rstrip

2007-11-22 Thread kyo guan
Hi : Please look at this code: >>> 'exe.torrent'.rstrip('.torrent') 'ex'<- it should be 'exe', why? but this is a right answer: >>> '120.exe'.rstrip('.exe') '120' <-- this is a right value. there is a bug in the rstr