Remove characters before and including _ in python 2.7

To get all text on a line after a underscore character, split on the first _ character and take the last element of the result:

line.split('_', 1)[-1]

This will also work for lines that do not have an underscore character on the line.

Demo:

>>> 'Grp25_QTY47               5'.split('_', 1)[-1]
'QTY47               5'
>>> 'No underscore'.split('_', 1)[-1]
'No underscore'

Translating this to your code:

import textwrap

ta_to = ta_from.copyta(status=endstatus)
with botslib.opendata(ta_from.filename,'r') as infile:
    with botslib.opendata(str(ta_to.idta),'wb') as tofile:
        for line in textwrap.wrap(next(infile), 640):
            line = line.split('_', 1)[-1]
            tofile.write(line + '\r\n')

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)