使用 Python,如何在特定字符串出现的位置拆分文本文件?
我尝试使用.split()
但它给出了一个错误:AttributeError: 'file' object has no attribute 'split'
代码:
book = open('finn.txt')
x = book.split('*** START OF THIS PROJECT GUTENBERG EBOOK HUCKLEBERRY FINN ***')
文件:finn.txt
Title: Adventures of Huckleberry Finn, Complete
Author: Mark Twain (Samuel Clemens)
*** START OF THIS PROJECT GUTENBERG EBOOK HUCKLEBERRY FINN ***
Produced by David Widger
期望的输出
Produced by David Widger