[EMAIL PROTECTED] a écrit :
> On Sep 18, 1:31 pm, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:
> 
>>On 9/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>>
>>
>>>If I have a file name: AVC1030708.14.  How do I strip out certain
>>>characters from the file name?  I am so used to using MID, LEFT, and
>>>RIGHT functions, that I have no idea how to do this in python?  I have
>>>had trouble as well with most newbies on finding the help.  But I have
>>>used the command line built in help, but with no luck.  Thanks.
>>
>>>Kou
>>
>>Do you want to strip out specific characters, characters in specific
>>positions, or characters matching certain patterns?
> 
> 
> Yes, I want specific characters in specific positions.
> 
Err... Sorry, but something is not clear here. When you say "strip out", 
  you mean "get rid of", or "access to" ? For what I remember of basic, 
I guess it's the second answer, so:

 >>> fname = "AVC1030708.14"
 >>> print fname[0]
A
 >>> print fname[-1]
4
 >>> print fname[2:4]
C1
 >>> print fname[2:-4]
C103070
 >>>

etc...

Also and while we're at it, you also have:
 >>> fname.split('.')
['AVC1030708', '14']
 >>> fname.split('.')[0]
'AVC1030708'
 >>> fname.split('.')[1]
'14'
 >>> fname.strip('4')
'AVC1030708.1'
 >>> fname.strip('A')
'VC1030708.14'
 >>> fname.lstrip('A')
'VC1030708.14'
 >>> fname.rstrip('4')
'AVC1030708.1'
 >>> fname.rstrip('41.')
'AVC1030708'

etc...

HTH



-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to