cython http://cython.org/ 算是 pyrex 的发展,用来方便编写 python 的 C 扩展。
可以将附件俩脚本加上可执行权限丢在 ~/bin,
安装 cython, python-pyrex, python-dev 后, 可以执行类似 mkcython.sh -e tesc.py 来生成可执行文件
如
$ ls
tesc.py
$ mkcython.sh -e tesc.py
+ cython tesc.py
++ python-config --cflags
++ python-config --ldflags
+ gcc -I/usr/include/python2.6 -I/usr/include/python2.6
-fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes
-L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm -lpython2.6
tesc.c -s -o tesc
$ ls
tesc tesc.c tesc.py
$ ./tesc
1 2 3 4 5 6 7 8 9 10
On 6月1日, 下午5时32分, 袁雁波 <yanbo.y...@gmail.com> wrote:
> 帅!
> 用了一下,效果非常的好
> 我把项目中的几个关键模块全部编译成pyd了,这样一定程度上,至少核心源码不会泄漏了
> 谢谢
>
> 2009/6/1 Jiahua Huang <jhuangjia...@gmail.com>
>
>
>
> > 以前贴过一次 pyrex 的,
> > 现在再贴一次 cython 的吧
>
> > cythonhttp://cython.org/算是 pyrex 的发展,用来方便编写 python 的 C 扩展。
> > > 1 2 3 4 5 6 7 8 9 10- Hide quoted text -
>
> - Show quoted text -
这个可以说是用来
提高单个 python 程序的速度,
或者用来隐藏源码
2009/6/2 一凡猪 <vermil...@gmail.com>:
> 很有意思.
> 那这样编译后,放到没有安装python的主机也可以执行了?
>
你确定你的文件是utf-8的编码么?
--
Best Regards,
Leo Jay
还有,是否可以指定输出到每个文件,而不是复写原py?
另建议,提交官方?
On Jun 1, 4:18 pm, Jiahua Huang <jhuangjia...@gmail.com> wrote:
> 以前贴过一次 pyrex 的,
> 现在再贴一次 cython 的吧
>
> cythonhttp://cython.org/算是 pyrex 的发展,用来方便编写 python 的 C 扩展。
>
> 可以将附件俩脚本加上可执行权限丢在 ~/bin,
>
> 安装 cython, python-pyrex, python-dev 后, 可以执行类似 mkcython.sh -e tesc.py 来生成可执行文件
>
> 如
>
> $ ls
> tesc.py
>
> $ mkcython.sh -e tesc.py
> + cython tesc.py
> ++ python-config --cflags
> ++ python-config --ldflags
> + gcc -I/usr/include/python2.6 -I/usr/include/python2.6
> -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes
> -L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm -lpython2.6
> tesc.c -s -o tesc
>
> $ ls
> tesc tesc.c tesc.py
>
> $ ./tesc
> 1 2 3 4 5 6 7 8 9 10
>
> mkcython.sh
> 2KViewDownload
>
> mkpyrexc.sh
> 2KViewDownload
On Jun 1, 4:18 pm, Jiahua Huang <jhuangjia...@gmail.com> wrote:
> 以前贴过一次 pyrex 的,
> 现在再贴一次 cython 的吧
>
> cythonhttp://cython.org/算是 pyrex 的发展,用来方便编写 python 的 C 扩展。
>
> 可以将附件俩脚本加上可执行权限丢在 ~/bin,
>
> 安装 cython, python-pyrex, python-dev 后, 可以执行类似 mkcython.sh -e tesc.py 来生成可执行文件
>
> 如
>
> $ ls
> tesc.py
>
> $ mkcython.sh -e tesc.py
> + cython tesc.py
> ++ python-config --cflags
> ++ python-config --ldflags
> + gcc -I/usr/include/python2.6 -I/usr/include/python2.6
> -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes
> -L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm -lpython2.6
> tesc.c -s -o tesc
>
> $ ls
> tesc tesc.c tesc.py
>
> $ ./tesc
> 1 2 3 4 5 6 7 8 9 10
>
> mkcython.sh
> 2KViewDownload
>
> mkpyrexc.sh
> 2KViewDownload
好奇怪呀,
添加那段是
grep -q '^def *main(' "$PYX" || echo 'def main(): pass' >> "$PYX"
通常在 bash 解释器下 echo 默认就会有 \n 的,
要不试试改为
grep -q '^def *main(' "$PYX" || echo -e 'def main(): pass\n' >> "$PYX"
On Jun 2, 3:06 pm, Jiahua Huang <jhuangjia...@gmail.com> wrote:
> 2009/6/2 Oyster <lepto.pyt...@gmail.com>:
不过先前有 MAC 用户给出的源码也是代码末尾没回车,导致 diff 报错。
btw: 虽然你说没有意义,
不过还是认为源码末尾应该有换行的,
起码 C 的规范里说了
(处理 # include 等)
PEPs 没仔细看,不过觉得应该也有要求的。
2009/6/2 Oyster <lepto....@gmail.com>:
见 http://paste.ubuntu.org.cn/15177
$ cat ~/.vimrc
" 自动补全命令时候使用菜单式匹配列表
set wildmenu
" 允许退格键删除
set backspace=2
" 启用鼠标
set mouse=a
" 文件类型
filetype on
filetype plugin on
filetype indent on
" 设置编码自动识别, 中文引号显示
"set fileencodings=utf-8,cp936,big5,euc-jp,euc-kr,latin1,ucs-bom
set fileencodings=utf-8,gbk,ucs-bom
set ambiwidth=double
" 移动长行
nnoremap <Down> gj
nnoremap <Up> gk
set lz
" 让编辑模式可以中文输入法下按:转到命令模式
nnoremap : :
" 高亮
syntax on
" 设置高亮搜索
set hlsearch
" 输入字符串就显示匹配点
set incsearch
" 输入的命令显示出来,看的清楚些。
set showcmd
" 折叠
if has("gui_running")
set foldenable foldminlines=0 foldmethod=manual foldlevel=9999
foldcolumn=0 fdm=syntax
autocmd FileType python set foldcolumn=5 fdm=indent
autocmd FileType c set foldcolumn=6 fdm=syntax
autocmd FileType cpp set foldcolumn=6 fdm=syntax
endif
" 打开当前目录文件列表
map <F3> :e .<CR>
" Taglist
let Tlist_File_Fold_Auto_Close=1
set updatetime=1000
map <F4> :Tlist<CR>
" 按 F8 智能补全
inoremap <F8> <C-x><C-o>
" vim 自动补全 Python 代码
" 来自http://vim.sourceforge.net/scripts/script.php?script_id=850
autocmd FileType python set complete+=k~/.vim/tools/pydiction
autocmd FileType python set shiftwidth=4 tabstop=4 expandtab
" 自动使用新文件模板
autocmd BufNewFile *.py 0r ~/.vim/template/simple.py
autocmd FileType html set shiftwidth=4 tabstop=4 expandtab
autocmd BufNewFile *.html 0r ~/.vim/template/simple.html
autocmd BufRead *.defs set filetype=scheme
"要在命令行上实现 Emacs 风格的编辑操作: >
" 至行首
cnoremap <C-A> <Home>
" 后退一个字符
cnoremap <C-B> <Left>
" 删除光标所在的字符
cnoremap <C-D> <Del>
" 至行尾
cnoremap <C-E> <End>
" 前进一个字符
cnoremap <C-F> <Right>
" 取回较新的命令行
cnoremap <C-N> <Down>
" 取回以前 (较旧的) 命令行
cnoremap <C-P> <Up>
" 后退一个单词
cnoremap <Esc><C-B> <S-Left>
" 前进一个单词
cnoremap <Esc><C-F> <S-Right>
"Format the statusline
"Nice statusbar
set laststatus=2
set statusline=
set statusline+=%2*%-3.3n%0*\ " buffer number
set statusline+=%f\ " file name
set statusline+=%h%1*%m%r%w%0* " flag
set statusline+=[
if v:version >= 600
set statusline+=%{strlen(&ft)?&ft:'none'}, " filetype
set statusline+=%{&encoding}, " encoding
endif
set statusline+=%{&fileformat}] " file format
if filereadable(expand("$VIM/vimfiles/plugin/vimbuddy.vim"))
set statusline+=\ %{VimBuddy()} " vim buddy
endif
set statusline+=%= " right align
"set statusline+=%2*0x%-8B\ " current char
set statusline+=0x%-8B\ " current char
set statusline+=%-14.(%l,%c%V%)\ %<%P " offset
pydiction好像04年就不更新了。不知道pysmell怎么样呢。
我只是不明白为什么vim默认里面没有自动感知。
有朋友推荐用autocomplpop,来实现自动感知。
會有問題:
這一句被無視了
執行了這裏的main()
主程序反而沒被執行
#myprog.py
from mylib import *
def main():
print 'main'
if __name__ == '__main__':
main()
mylib.py是這樣的:
#mylib.py
def myfunc(var):
print var
def main():
myfunc('test')
if __name__ == '__main__':
main()
直接執行myprog.py,執行的是.py裏面的那個main函數,這是預期的結果;
mkcython.sh -e myprog.py
生成的可執行文件,執行的是mylib.py裏面的那個main函數