#实现将某个目录下面的py后缀名的文件修改成asp
import os,string
def s_rename(path,old_ext,new_ext):
for (path, dirs, files) in os.walk(path):
for filename in files:
ext=os.path.splitext(filename)[1]
if (cmp(ext,old_ext)==0):
newname=filename.replace(old_ext,new_ext)
oldpath=path+"\\"+filename
newpath=path+"\\"+newname
print "oldpath:"+oldpath+""
print "newpth:"+newpath+""
try:
os.rename(oldpath, newpath)
except ValueError:
print "Error when rename the file " + oldpath
except NameError:
print "Error when rename the file " + oldpath
except OSError:
#print OSError
print newpath + " The file is already exist!"
if __name__ == '__main__':
s_rename("E:\\func",".py",".asp")
|
import os,string
def Denary2Binary(n):
bStr = ''
if n < 0: raise ValueError, "must be a positive integer"
if n == 0: return '0'
while n > 0:
bStr = str(n % 2) + bStr
n = n >> 1
return bStr
if __name__ == '__main__':
print Denary2Binary(8)
print int('10',2)
阅读(1332) | 评论(0) | 转发(0) |