python脚本生成器

#!/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)
	

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值