易截截图软件、单文件、免安装、纯绿色、仅160KB

python之学习类:python修改文件名


下面是对某文件夹下多个文件下指定文件换名字的实例(为了换名字,因为懒得手动改,折腾了一会搞出来的)
原理很简单,换文件名的话指定path就行 ,具体的自己看吧,仅供参考!
#-*- coding:utf-8 -*-
import os,sys
#=======================================
##对多个文件夹下的文件(夹)进行处理
#=======================================
def getdirNames(path):
    dirNames = os.listdir(path)
    return dirNames
def isDir(dirNames,path):
    for item in dirNames:
        dir =  os.path.join(path,item)
        if(os.path.isdir(dir)):
            dirAddress.append(dir)
            file = getdirNames(dir)
            isDir(file,dir)
        else:
            if 'png' in item:
                fileAddress.append(dir)
    return fileAddress
#=======================================
##对某个文件夹下面的文件进行处理
#=======================================
def fil(filename):
    mapdir = filename[-1:]
    mapname = filename[:-2].replace('0','')
    changename = mapname[::-1].zfill(8)[::-1]
    rename = changename+'_'+mapdir
    return rename
if __name__ == '__main__':
    #此处添加需要转换名字的文件夹路径(文件夹下面可以有多个文件夹),【例如:在此我将“0103020202_0.png”转换成“13222000_0.jpg:】
    path0 = r'F:\python\20100412\game\data\images\Object\World\Road'
    dirAddress = []
    fileAddress = []
    dirNames = getdirNames(path0)
    isDir(dirNames,path0)
    print fileAddress
    for i in range(len(fileAddress)):
 &


相关文档:

example of python operator overloadind

And last here is the overload operators example:
# map() takes two (or more) arguments, a function and a list to apply the function to
# lambda can be put anywhere a function is expected
# map() calls lambada for every element in the self list
# since Vector has overloaded __getitem__ and __len_ ......

python动态导入模块、检查模块是否安装

参考链接:http://www.woodpecker.org.cn/diveintopython/functional_programming/dynamic_import.html
一 动态导入模块
Python的import不能接受变量,所以应该用 __import__函数来动态导入。
如下的代码无法正常导入模块
modules = ['OpenSSL', 'Crypto', 'MySQLdb', 'sqlite3', 'zope.interface', 'pyasn1', 'twisted ......

python的一些操作

# coding=gb2312
# 用中文注释前务必加上第一行
# 求模运算符,和C语言一样
print 10%9
# 整数相除仍然是整数
print 5/2
# 2后加上.就变成浮点数了
print 5/2.
# **表示求幂运算
print 7**4
# 函数用时要加上module.function
import math
print math.floor(19.8)
# 函数名也可以成为变量
func = math.floor
......

Python学习笔记 高级主题

1.列表的递归---用于输出列表字符串中的每个元素 >>> def printList(L):
    #如果为空,则什么都不做
    if not L:
        return
    #如果是链表,则对第一个元素调用printList函数
 & ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号