String Manipulation

Brandon Beck bbeck at NOSPAM.austin.rr.com
Tue Jul 15 18:31:10 EDT 2003


I know a few people replied to this already, but here's one additional
possibility.  If the data in string1 is a file path for your platform,
then you can use the os.path module.

>>> import os.path
>>> os.path.split("aaa/bbb/ccc/dd")
('aaa/bbb/cc', 'dd')
>>> os.path.splitext("filename.ext")
('filename', '.ext')

The other suggestions will of course work, but if you data is a file
path, then using the os.path module should be a more portable solution.

Brandon



"lamar_air" <lamar_air at hotmail.com> wrote in message
news:2c6431ab.0307151223.4173c4ee at posting.google.com...
> I need a piece of code that takes a string like this string1 =
> "aaa/bbb/ccc/dd" and extracts a string containting the character after
> the last "/"
>
> So for this example the result would be "dd"
>
> like this:
> for i=0; string1.right(i) != '/'; i++
>
> result = string1.mid(i, string1.length())
>
> but in python.






More information about the Python-list mailing list