python小函数

python小函数

# coding:gbk

import  os,sys,time

def  get_ext(fileName):
    pos 
=  fileName.rfind( " . " )
    
if  pos  !=- 1 :
        
return  fileName[pos:].lower()
    
else :
        
return  None

def  str2int(v):
    
try :v  =  int(v)
    
except :v  =  0
    
return  v

def  mod(x,y):
    
return  float(x) / y

def  printf(format, * args):
    sys.stdout.write(format
% args)

def  sprintf(format, * args):
    
return  format % args

def  exit_delay(num):
    secnod 
=  num
    text 
=  r " after (%02d) secnod exit. "
    length 
=  len(text) - 2
    back 
=   ""
    
for  i  in  range(length):
        back 
=  back  +   " \b "
    
while  (secnod):
        sys.stdout.write(text
% secnod)
        sys.stdout.flush()
        time.sleep(
1 )
        sys.stdout.write(back)
        secnod 
=  secnod  - 1 ;
    sys.stdout.write(text
% secnod)
    sys.stdout.write(
" \r\n " )
    
def  unlink(filename):
    
try :
        os.remove(filename)
        printf(
" 删除文件(%s)成功 \r\n " ,filename)
    
except  WindowsError,e:
        
if  e.errno == 2 :
            printf(
" 文件(%s)不存在 \r\n " ,filename)
            
def  A(n):
    c 
=   1
    
for  i  in  range(n):
        c 
*=  i + 1
    
return  c

def  C(n,m):
    
return  A(n) / A(n - m) / A(m)            

你可能感兴趣的:(python小函数)