#!/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, sys
print '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.close
os.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.close
os.chmod(x,stat.S_IRWXU)
python脚本生成器
最新推荐文章于 2022-07-19 11:13:21 发布