Based on this example of a line from a file
1:alpha:beta
I’m trying to get python to read the file in and then line by line print whats after the 2nd ':'
import fileinput
#input file
x = fileinput.input('ids.txt')
strip_char = ":"
for line in x:
strip_char.join(line.split(strip_char)[2:])
This produces no results, however from a console session on a single line it works fine
Python 2.7.3rc2 (default, Apr 22 2012, 22:35:38)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
data = '1:alpha:beta'
strip_char = ":"
strip_char.join(data.split(strip_char)[2:])
'beta'
What am i doing wrong please? Thanks
For the data format given this will work:
For
'1:alpha:beta'the output would be'beta'For
'1:alpha:beta:gamma'the output would be'beta:gamma'(Thanks for @JAB pointing this out)