python脚本生成器

来源:互联网 发布:淘宝宝贝描述代码下载 编辑:程序博客网 时间:2024/06/08 01:03
#!/usr/bin/env python#This script aims to help Project Euler python programmers to either create a given number of python scripts named from x.py to y.py (both x and y are numbers typed in) or create a file named by yourself. Each script is generated with the string '''#!/usr/bin/nev python''' automatically put in the first line.#Credits: Heian Senlin#License: This script is distributed under the GNU GENERAL PUBLIC LICENSE, and fully committed to the free software spirit: you are encouraged to use it, improve it and pass it on.#Warning: Do NOT run this script in some important directories for fun! This may spoil your work in the directory.import os, stat, sysprint 'Type two numbers, \n5 and 10 for example, \nand this script will create files named from 5.py to 10.py in the current directory.'print '\nBe careful, \nplease do NOT test this script in some important directories for fun! \nDoing this may spoil your work in that directory.\n'x = input("So, you want to create files numbered from ?.py\nOr you may want to type 0 to create a file by naming it manually:") if x==0:z=raw_input('Please input your file name:\n')f = file(z+'.py','a')f.write('#!/usr/bin/python\n\n')#single '\n' wont work. DK why.f.write('\n\nraw_input()')f.closeos.chmod(z+'.py',stat.S_IRWXU)sys.exit(0)y = input('from '+str(x)+'.py to ?.py :')for i in xrange(x,y+1):x= str(i) + '.py'f = file(x,'a')#'w' will work, but rather dangerous. f.write('#!/usr/bin/python\n\n')#single '\n' wont work. DK why.f.write('\n\nraw_input()')f.closeos.chmod(x,stat.S_IRWXU)

原创粉丝点击