您可以使用模式在文件中添加一些内容rb+
import re
ss = '''
0, On a scale of 1-5, how are you feeling today?,3,5,4,5,4,3,
1, What activities can improve your mood?,eat,sleep,drink,talk,tv,
2, What is worse condition for you?,humidity,dry,cold,heat,
'''
# not needed for you
with open('tryy.txt','w') as f:
f.write(ss)
# your code
line_appendenda = 1
x_to_append = 'weather'
with open('tryy.txt','rb+') as g:
content = g.read()
# at this stage, pointer g is at the end of the file
m = re.search('^%d,[^\n]+$(.+)\Z' % line_appendenda,
content,
re.MULTILINE|re.DOTALL)
# (.+) defines group 1
# thanks to DOTALL, the dot matches every character
# presence of \Z asserts that group 1 spans until the
# very end of the file's content
# $ in ther pattern signals the start of group 1
g.seek(m.start(1))
# pointer g is moved back at the beginning of group 1
g.write(x_to_append)
g.write(m.group(1))