我想通过只输入一个文件来输入两个名称相同但扩展名不同的文件:
tkMessageBox.showinfo(title="Info",message="Please input both the .rwh file")
# the filetype mask (default is all files)
mask = \
[("files","*.rwh"),
("All files","*.*")]
title = 'Open'
files = askopenfilenames(initialdir=self.initial_dir, filetypes=mask,title=title)
然后是我不会怎么做的部分。它必须通过读取文件输入来创建一个文件对象,然后通过读取名称创建另一个具有相同名称但不同扩展名 (.row) 的文件对象。
然后我调用了一个使用两个文件对象的函数。
文件具有不同的扩展名,因为它们包含不同的信息,两个文件都在同一个文件夹中。
请您参考如下方法:
os.path.splitext允许您获取根名称:
>>> import os
>>> filename = '/my/filename.rwh'
>>> root, ext = os.path.splitext(filename)
>>> root
'/my/filename'
>> root + '.row'
'/my/filename.row'
