每次去創(chuàng)建py文件的時(shí)候要好幾步歌径、還要再加上utf-8總感覺麻煩验庙、就寫了這個(gè)偷懶袜刷。
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