使用python脚本快速创建一个文件并打开

每次去创建py文件的时候要好几步、还要再加上utf-8总感觉麻烦、就写了这个偷懒。

from sys import argv
import os
from os.path import exists

script, newFileName = argv

isExist = exists(newFileName)
print isExist

if isExist == True :
    print "the file %s is haved." % newFileName

else :
    print "no have"
    theFile = open(newFileName, 'a+')
    theFile.write("# -*- coding:utf-8 -*- \n")
    theFile.close()

    os.system( "open " + newFileName)


# create a new file write "# -*- coding:utf-8 -*- \n" and open it
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容