list_append = [] with open('filename') as f: for line in f: t_line = line.split(' ') if (t_line[0] == 'ABC'): print(t_line[1]) list_append.append(t_line[1])
-----Original Message----- From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara....@python.org] On Behalf Of durgadevi1 Sent: 15 April 2016 13:13 To: python-list@python.org Subject: How to print a part of a string? Hello all, I have another homework problem. I have a textfile. It contains lines of string. I am required to only print out a certain part of the string. For example the textfile contain: ABC XXXXX NNNNN BCD QQQQQ EEEEE ABC WWWWW AAAAA I need to print all the parts that come after only ABC. That means I need to print only XXXXX from the first line and WWWWW from the second line. I'm not sure of what code to use to achieve that. -- https://mail.python.org/mailman/listinfo/python-list This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. -- https://mail.python.org/mailman/listinfo/python-list