Python Cut Example

user735304 picture user735304 · May 3, 2011 · Viewed 38.4k times · Source

I'm looking for a way in python to achieve similar functionality to the unix cut utility. I know I can make a system call and process my data that way but I'd like to make it a bit more "pythonic" and do it with python libraries.

Example text

abcde:12345

I'd like to delimit on : and keep the second field:

cut -d':' -f2

to produce:

12345

thoughts?

Answer

manojlds picture manojlds · May 3, 2011

You can do:

string.split(":")[1]

where string is your text