#!/usr/local/bin/python2.5 #-*- coding: gbk -*- from struct import*
class BBFile: def__init__(self): pass
def _contactblock(self, name, phone, uid): s ='' # name name = name.encode("utf-16be") s += pack('<HB', len(name)+1, 0xa0) s += pack('<B', 0x01) + name # ff * 8 s += pack('<HB', 8, 0x54) s +='\xff'*8 # uid s += pack('<HBI', 4, 0x55, uid) # phone phone = phone.encode("gbk") s += pack('<HB', len(phone)+1, 0x08) s += phone +'\x00' return s
def save(self, filename, us, dbID=0, dbVer=0): hf = open(filename, "w+b") rs, uid =1, 363797835# 鍒濆鍊?/span> for u in us: s = self._contactblock(u[0], u[1], uid) h = pack('<HIBHI', dbID, len(s)+7, dbVer, rs, uid) hf.write(h + s) uid +=8# rs +=1# hf.close()
4. 鍙兘鐨勯敊璇強瑙e喅 a. 鍦╲s 200x 涓?debug 妯″紡鍑虹幇閾炬帴闂 extmodule.obj : error LNK2019: unresolved external symbol __imp___Py_Dealloc referenced in function _PySwigObject_format extmodule.obj : error LNK2019: unresolved external symbol __imp___Py_NegativeRefcount referenced in function _PySwigObject_format extmodule.obj : error LNK2001: unresolved external symbol __imp___Py_RefTotal extmodule.obj : error LNK2019: unresolved external symbol __imp___PyObject_DebugFree referenced in function _PySwigObject_dealloc extmodule.obj : error LNK2019: unresolved external symbol __imp___PyObject_DebugMalloc referenced in function _PySwigObject_New extmodule.obj : error LNK2019: unresolved external symbol __imp__Py_InitModule4TraceRefs referenced in function _init_extmodule
]]>浣跨敤 python 鍐?COM http://www.shnenglu.com/bigsml/archive/2008/08/14/58851.html娉℃場鐗?/dc:creator>娉℃場鐗?/author>Thu, 14 Aug 2008 09:02:00 GMThttp://www.shnenglu.com/bigsml/archive/2008/08/14/58851.htmlhttp://www.shnenglu.com/bigsml/comments/58851.htmlhttp://www.shnenglu.com/bigsml/archive/2008/08/14/58851.html#Feedback0http://www.shnenglu.com/bigsml/comments/commentRss/58851.htmlhttp://www.shnenglu.com/bigsml/services/trackbacks/58851.html1. com 璋冪敤紺轟緥(浣跨敤Windows Media Player 鎾斁闊充箰)
class PythonUtilities: _public_methods_ = [ 'SplitString' ] _reg_progid_ ="PythonDemos.Utilities" # NEVER copy the following ID # Use "print pythoncom.CreateGuid()" to make a new one. _reg_clsid_ ="{41E24E95-D45A-11D2-852C-204C4F4F5020}"
# Add code so that when this script is run by # Python.exe, it self-registers. if__name__=='__main__': print"Registering COM server" import win32com.server.register win32com.server.register.UseCommandLine(PythonUtilities)
- 娉ㄥ唽/娉ㄩ攢Com
Command-Line Option
Description
The default is to register the COM objects.
--unregister
Unregisters the objects. This removes all references to the objects from the Windows registry.
--debug
Registers the COM servers in debug mode. We discuss debugging COM servers later in this chapter.
--quiet
Register (or unregister) the object quietly (i.e., don't report success).
inproc server 鏄氳繃pythoncom25.dll 瀹炵幇 local server 閫氳繃localserver.py 瀹炵幇 com 瀵瑰簲鐨刾ython 婧愭枃浠朵俊鎭湪 PythonCOMPath & PythonCOM
4. 浣跨敤闂 鐢≒HP 鎴栬?c 璋冪敤com 鐨勬椂鍊?br>
<?php $com=new COM("PythonDemos.Utilities"); $rs=$com->SplitString("a b c"); foreach($rsas$r) echo$r."\n"; ?>
浼氱鍒頒笅闈㈢殑涓浜涢敊璇? pythoncom error: PythonCOM Server - The 'win32com.server.policy' module could not be loaded. <type 'exceptions.ImportError'>: No module named server.policy pythoncom error: CPyFactory::CreateInstance failed to create instance. (80004005)
鍙互閫氳繃2縐嶆柟寮忚В鍐? a. 璁劇疆鐜 PYTHONHOME = D:\usr\Python 鍙﹀鍦╟ ++ 浣跨敤python 鐨勬椂鍊? 濡傛灉import module 鍑虹幇閿欒 'import site' failed; use -v for traceback 鐨勮瘽, 涔熷彲浠ラ氳繃璁劇疆榪欎釜鍙橀噺瑙e喅.
b. 涓篶om 鐢熶駭exe, dll 鍙墽琛屾枃浠? setup.py 浠g爜濡備笅 :
from distutils.core import setup import py2exe import sys import shutil # Remove the build tree ALWAYS do that! shutil.rmtree("build", ignore_errors=True) # List of modules to exclude from the executable excludes = ["pywin", "pywin.debugger", "pywin.debugger.dbgcon", "pywin.dialogs", "pywin.dialogs.list"] # List of modules to include in the executable includes = ["win32com.server"] # ModuleFinder can't handle runtime changes to __path__, but win32com uses them try: # if this doesn't work, try import modulefinder import py2exe.mf as modulefinder import win32com for p in win32com.__path__[1:]: modulefinder.AddPackagePath("win32com", p) for extra in ["win32com.shell", "win32com.server"]: #,"win32com.mapi" __import__(extra) m = sys.modules[extra] for p in m.__path__[1:]: modulefinder.AddPackagePath(extra, p) except ImportError: # no build path setup, no worries. pass # Set up py2exe with all the options setup( options = {"py2exe": {"compressed": 2, "optimize": 2, #"bundle_files": 1, "dist_dir": "COMDist", "excludes": excludes, "includes": includes}}, # The lib directory contains everything except the executables and the python dll. # Can include a subdirectory name. zipfile = None, com_server = ['PythonDemos'], # 鏂囦歡鍚?! )