【发布时间】:2020-09-08 17:14:30
【问题描述】:
我有以下代码:
ctypes.windll.user32.MessageBoxW(0, "Please choose a file directory", "File directory", 1)
EDS_database_path = filedialog.askdirectory()
EDS_answer = simpledialog.askstring("Input", "Please enter the ID")
EDS_files_list = glob.glob(EDS_database_path+'/**'+EDS_answer+'**', recursive = True)
print(EDS_files_list)
在我得到的输出中:
['X:/data/Folder\\afilewithIDnumber.txt','X:/data/Folder\\anotherfilewithIDnumber.txt',]
因此该函数运行良好,但我想摆脱“\”并将其替换为“/”,因为我明确希望在我的函数中执行此操作。
【问题讨论】:
-
不确定是否可以修改
glob的行为,但您可以轻松地使用例如[filename.replace('\\', '/') for filename in EDS_files_list]