Я до сих пор не могу понять, как разрезать «строку», а затем захватить всю строку, найдя какую-то «строку». это то, что я делаю до сих пор:
content.txt :
#Try to grab this line start
#Try to grab this line 1
#Try to grab this line 2
#Try to grab this line 3
#Try to grab this line 4
#Try to grab this line 5
#Try to grab this line 6
#Try to grab this line end
#Try to grab this line 7
#Try to grab this line 8
мой сценарий:
f_name = open('D:\PROJECT\Python\content.txt', "r").read()
start = f_name.find('start')
end = f_name.find('end')
jos = slice(start, end)
make = open('D:\PROJECT\Python\result.txt', "w")
make.write(f_name[jos])
результат вывода.txt:
start
#Try to grab this line 1
#Try to grab this line 2
#Try to grab this line 3
#Try to grab this line 4
#Try to grab this line 5
#Try to grab this line 6
#Try to grab this line
вывод, который мне нужен:
#Try to grab this line start
#Try to grab this line 1
#Try to grab this line 2
#Try to grab this line 3
#Try to grab this line 4
#Try to grab this line 5
#Try to grab this line 6
#Try to grab this line end
спасибо прежде, я надеюсь, что мое объяснение было ясно. Любая помощь будет принята с благодарностью!