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
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' <
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','.
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'
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
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
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'
"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'
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...
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
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
11 matches
Mail list logo