我正在尝试保存.txt,但是会出现此错误:TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper
代码如下:
def saveas():
window.filename = filedialog.asksaveasfile(initialdir = "/",title = "Select file",filetypes = (("text files","*.txt"),("all files","*.*")))
file=open(window.filename, 'w')
file.writelines(escritura.get('1.0', END))
file.close()
print(escritura.get('1.0', END))
如果您知道,请帮助我
答案 0 :(得分:1)
使用startTime := time.Now()
// startTime will be in UTC and the timezone
// will be set to whatever your local timezone is
// load the location you want to display the time in
loc, _ := time.LoadLocation("Europe/Berlin")
// set timezone and display:
timeToDisplay := startTime.In(loc).String()
fmt.Println(timeToDisplay)
属性访问文件-> .name
。
例如:
window.filename.name
答案 1 :(得分:0)
escritura.get('1.0', END)
可能已经打开了,所以也许您应该执行escritura.get('1.0', END).read()
,因为我还不能发表评论,所以您可以type(escritura.get('1.0', END))