Chinaunix首页 | 论坛 | 博客
  • 博客访问: 29334365
  • 博文数量: 2065
  • 博客积分: 10377
  • 博客等级: 上将
  • 技术积分: 21525
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-04 17:50
文章分类

全部博文(2065)

文章存档

2012年(2)

2011年(19)

2010年(1160)

2009年(969)

2008年(153)

分类: Python/Ruby

2010-12-26 18:22:02

#实现将某个目录下面的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)
阅读(1335) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~