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

2016-08-09  本文已影响482人  Nothing_lu

每次去创建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
上一篇下一篇

猜你喜欢

热点阅读