分类 Python编程 下的文章

使用py2exe生产windows可执行程序时,报错:error: [Errno 2] No such file or directory: 'MSVCP90.dll'
原脚本:

#!/usr/bin/env python
__author__ = 'key1088'
__date__ = '15-3-7'
from distutils.core import  setup
import py2exe
setup(console=["overtime.py"])

使用生产命令:

F:workdirpython1>D:Python27python.exe mysetup.py  py2exe
running py2exe
creating F:workdirpython1build
creating F:workdirpython1buildbdist.win32
creating F:workdirpython1buildbdist.win32winexe
creating F:workdirpython1buildbdist.win32winexecollect-2.7
creating F:workdirpython1buildbdist.win32winexebundle-2.7
creating F:workdirpython1buildbdist.win32winexetemp
creating F:workdirpython1dist
*** searching for required modules ***
*** parsing results ***
creating python loader for extension 'unicodedata' (D:Python27DLLsunicodedata.pyd -> unicodedata.pyd)
creating python loader for extension 'wx._misc_' (D:Python27libsite-packageswx-3.0-mswwx_misc_.pyd -> wx._misc_.pyd)
creating python loader for extension 'select' (D:Python27DLLsselect.pyd -> select.pyd)
creating python loader for extension 'wx._windows_' (D:Python27libsite-packageswx-3.0-mswwx_windows_.pyd -> wx._windows_.pyd)
creating python loader for extension '_hashlib' (D:Python27DLLs_hashlib.pyd -> _hashlib.pyd)
creating python loader for extension 'wx._gdi_' (D:Python27libsite-packageswx-3.0-mswwx_gdi_.pyd -> wx._gdi_.pyd)
creating python loader for extension 'wx._controls_' (D:Python27libsite-packageswx-3.0-mswwx_controls_.pyd -> wx._controls_.pyd)
creating python loader for extension '_sqlite3' (D:Python27DLLs_sqlite3.pyd -> _sqlite3.pyd)
creating python loader for extension 'bz2' (D:Python27DLLsbz2.pyd -> bz2.pyd)
creating python loader for extension 'wx._core_' (D:Python27libsite-packageswx-3.0-mswwx_core_.pyd -> wx._core_.pyd)
*** finding dlls needed ***
error: [Errno 2] No such file or directory: 'MSVCP90.dll'

修改代码最后一行:

setup(console=["overtime.py"],options = { "py2exe":{"dll_excludes":["MSVCP90.dll"]}})

生成exe文件成功。
为了使py2exe打出来的可执行文件不出现中文乱码,每次输出要采用以下格式:print unicode("中文","utf-8")

1.最简单的加解密实例,字符串

import base64 

str1 = ‘hello'

print str1

str2 = base64.b64encode(str1)

print str2

str3 = base64.b64decode(str2)

print str3


2.针对文件加解密

import base64

f1=open('1.txt','r')

f2=open('2.txt','w')

base64.encode(f1,f2)               #加密,把f1的内容加密后写入f2

#base64.decode(f1,f2)            #解密,把f1的内容解密后写入f2

f1.close()

f2.close()


#!/usr/bin/env python
import os

dirpath="/data"
ext=".php"
key="system"
x=[]
y=[]
z=[]
def _isdir(path):
    for i in os.listdir(path):
        if os.path.isdir(path+'/'+i):
            _isdir(path+'/'+i)
        x.append(path+'/'+i)    
def _exfile(file):
    if file[-4:]==ext:
        y.append(file)
def _file(file1):
    f=open(file1,'r')
    for i in f:
        if not i.find(key) == -1:
            z.append(file1)
    f.close()
_isdir(dirpath)
for i in x:
    _exfile(i)
for a in y:
    _file(a)
abc=set(z)
for i in abc:
    print i