python写的掉空格数字字母的方法

def tripNumsAlpha():
    '''patt=re.compile(r"[^0-9]") then we would get like str1=''.join(re.findall(patt,"1215北京"))
       str1=>'北京'.Now you see what you want to .
    '''
    import re
    
    patt=re.compile(r"[^0-9a-zA-Z]")
    lis1=[]
    
    with open('D:\\clrename\\clearspace.txt', 'r') as f:
        for it in f.readlines():
            str1=''.join(re.findall(patt,it))
            lis1.append(str.lstrip(str1))

    f.close()
    
    with open('D:\\clrename\\clearspace-out.txt', 'w+') as f1:
        for it in lis1:
            print(it)
            f1.writelines(it)
    f1.close()
    print("-"*4+"Finished"+"-"*4)


你可能感兴趣的:(python)