在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Python/ python easygui文件保存問題

python easygui文件保存問題

terminal終端 顯示File types array cannot be empty
圖片描述

在IDEL運行沒問題,在終端運行不了
圖片描述

import easygui as g
import os

file_path = g.fileopenbox(default="*.txt")

with open(file_path) as old_file:
    title = os.path.basename(file_path)
    msg = "文件【%s】的內(nèi)容如下:" % title
    text = old_file.read()
    text_after = g.textbox(msg, title, text)
    
if text != text_after[:-1]:
    # textbox 的返回值會追加一個換行符
    choice = g.buttonbox("檢測到文件內(nèi)容發(fā)生改變,請選擇以下操作:", "警告", ("覆蓋保存", "放棄保存", "另存為..."))
    if choice == "覆蓋保存":
        with open(file_path, "w") as old_file:
            old_file.write(text_after[:-1])
    if choice == "放棄保存":
        pass
    if choice == "另存為...":
        another_path = g.filesavebox(default=".txt")
        if os.path.splitext(another_path)[1] != '.txt':
            another_path += '.txt'
        with open(another_path, "w") as new_file:
            new_file.write(text_after[:-1])```
回答
編輯回答
舊時光

估計是你的路徑變化了,終端沒有讀取到文件列表,導(dǎo)致報錯。

2018年3月26日 18:51
編輯回答
貓小柒
another_path = g.filesavebox(default=".txt")
更改為
another_path = g.filesavebox(default="指定路徑/*.txt")

問題就解決了~不知道為啥

2017年3月24日 17:57