之前提到 py2exe 可以建立單一的 exe image,今天馬上來測試了一下,果然很好用。順便還從 sample 裡學到把 image building action 嵌到原指令稿裡的小技巧:

def main():
    """
    Script invokation logic.
    """
    if len(sys.argv) > 1 and sys.argv[1] == "py2exe":
        setup_py2exe()
        sys.exit()

def setup_py2exe():
    from distutils.core import setup
    import py2exe

    setup(
           name         = "programname",
           description  = "Program Description",
           author       = "Yung-Yu Chen",
           author_email = "you@guess",
           console = [ __file__ ],
           version = __version__,
           options = { "py2exe": {"compressed"  : 1,
                                  "optimize"    : 2,
                                  "ascii"       : 1,
                                  "bundle_files": 1  } },
           zipfile = None
         )

if __name__ == '__name__':
    main()

不過 500 行指令稿作出來的一個 win32 exe image,只用到了一些 Numeric 函式和少數的標準模組,就包出了 2.x MB ("compressed":1 !!),每次都要載入好久 :)

為了一段解譯對應檔的程式,還想了這樣子的碼:

iwant = [ origstring ]
for splitter in [ ':', '=', ',', ';', None ]:
    newstrings = []
    for substring in iwant:
        newstrings.extend( substring.split(splitter) )
    iwant = newstrings

需要 6 行,或許有 60 分了吧;感覺上應該還有更短的寫法,把後四行代換成一行 (in Python 2.3)。re 說不定可以用一行解決 (倒是還沒時間去想)。

Fun.

Posted by yungyuc at 19:44, 0 comment, 0 trackback.

Python/Zope@Japan 的人好幸福的樣子,怎麼覺得他們常常出去玩呀 (happy)。

» continue reading
Posted by yungyuc at 18:11, 1 comments, 0 trackback.
Change to page (10 entries in each page): 1
© hover year to navigate month: powered by django