我正在尝试使用烧瓶来实现以下目标。
我的本地磁盘上有一个文件。它是一个大文件。所以我只想读取该文件的前 20 行。
如何读取文件并在浏览器上显示其内容?
任何指针..建议。谢谢
像这样的东西,应该工作
import webbrowser
# firstly you need to make write to an html file that will have the top 20 lines
# you can do that using
top_lines_file = open("shows.html", "w")
i = 1
while i in range(1,21):
top_lines_file.write("write something to the file")
i += 1
# this will iterate over the file and write to it 20 times
top_lines_file.close() # close the file
# now you need to pass the path of the html file to the webbrowser object
webbrowser.open("file://" + path/to/the/html/file)
# this will open the webbrowser with your html file