-1
다음을 위해 플라스크를 사용하려고합니다.파일의 내용을 읽고 브라우저에 표시하십시오.
내 로컬 디스크에 파일이 있습니다. 큰 파일입니다. 그래서 그 파일의 상위 20 줄을 읽고 싶습니다.
파일을 읽고 브라우저의 내용을 어떻게 표시합니까?
모든 포인터 .. 제안. 감사
이 같은다음을 위해 플라스크를 사용하려고합니다.파일의 내용을 읽고 브라우저에 표시하십시오.
내 로컬 디스크에 파일이 있습니다. 큰 파일입니다. 그래서 그 파일의 상위 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
잘 꽤 지속적으로 F 오픈 ("파일", 'R')와 파이썬 파일의 상위 20 선 ... 읽을 수 있습니다 : F를 .readlines [: 20] – Greg
그 파일의 상위 20 줄을 표시하기 위해 새 브라우저 창을여시겠습니까? –
@VirendraRajput : 네 .... 달콤한 것입니다. – Fraz