-2
我正在使用python 3.6.1。我是用Python自學的..我無法理解這個錯誤是什麼。寫入SSol.txt已成功,但是如何讀取SSol.txt?
這裏是我的代碼:
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
import urllib.request as request
def a():
url=("https://rp5.ru/%EC%95%88%EB%8F%99%EC%9D%98_%EB%82%A0%EC%94%A8,_%EA%B2%BD%EB%B6%81")
raw_data = request.urlopen(url).read() #Bytes
text = raw_data.decode("utf-8")
where = text.find('k;">')
start_where = where +4
end_start = where +7
f = open("SSSol.txt", 'w+')
decoded = int(text[start_where:end_start])
k=f.write(str(decoded))
t = str(f.readline())
messagebox.showinfo("hello",t)
ttk.Button(win, text="?", command=a).grid()
沒有出現錯誤,但是什麼也沒有輸出。
也許倒退文件'f.seek(0)'。或關閉文件並再次打開以便寫入。 –