如何让Windows自动添加扩展名到文件?

前端之家收集整理的这篇文章主要介绍了如何让Windows自动添加扩展名到文件?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
背景

我目前正在制作一个基本的文本编辑器,希望能够对Tkinter有一个基本的了解.我想创建自己的文件格式.mydoc我试图将文件类型更改为.mydoc为无.这是我目前拥有的代码

def openMe(self):
    #import the Tk file dialogue
    import tkFileDialog as tkF
    myFormat = [('Example Format','*.mydoc')]
    direct = tkF.askopenfilename(initialdir='D:\\',filetypes = myFormat,title = "Open a .mydoc")
    try:
        #open the text file
        txt_file = open(direct,"r")
    except UnboundLocalError,IOError:
        print "You either did not select a file,or the filetype was incorrect.\nPlease try again."
    #Read the data
    currentTEXT = txt_file.read()
    #Delete current text
    self.write.delete(0.0,END)
    #insert new text
    self.write.insert(0.0,currentTEXT)

>如何让计算机自动添加我的分机? (是的,我已经关闭了隐藏扩展选项.

技术规格

语言:Python 2.7.3

操作系统:Windows 7

解决方法

尝试使用defaultextension:

tkF.askopenfilename(initialdir='D:\\',filetypes=myFormat,title="Open a .mydoc",defaultextension=".mydoc")

猜你在找的Windows相关文章