![python簡潔技巧和常用參考__第1頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/15/88f6924f-bf82-4a53-ac4f-776572db0778/88f6924f-bf82-4a53-ac4f-776572db07781.gif)
![python簡潔技巧和常用參考__第2頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/15/88f6924f-bf82-4a53-ac4f-776572db0778/88f6924f-bf82-4a53-ac4f-776572db07782.gif)
![python簡潔技巧和常用參考__第3頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/15/88f6924f-bf82-4a53-ac4f-776572db0778/88f6924f-bf82-4a53-ac4f-776572db07783.gif)
![python簡潔技巧和常用參考__第4頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/15/88f6924f-bf82-4a53-ac4f-776572db0778/88f6924f-bf82-4a53-ac4f-776572db07784.gif)
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、python簡潔技巧和常用參考_ python文件支持中文 # -*- coding: utf-8 -*- 執(zhí)行shell指令 from subprocess import popen, pipe def run_cmd(cmd): #popen call wrapper.return (code, stdout, stderr) child = popen(cmd, stdin = pipe, stdout = pipe, stderr = pipe, shell = true) out, err = municate() ret = child.wait() return (ret, ou
2、t, err) 獵取當前python腳本文件所在路徑 import os os.path.split(os.path.realpath(_file_)0 json模塊 import的問題 try : import json except : import simplejson as json 用法json工具格式化json #python 2.7以下 echo hello:1 | python -m simplejson.tool #python 2.7及以上 echo hello:1 | python -m json.tool 一般調(diào)用步驟 py_initialize(); /初始化pyth
3、on環(huán)境 pyimport_importmodule(test); / 載入python模塊 pyobject_getattrstring(g_pmodule,test1); /獲得相應(yīng)python函數(shù)的pyobject pyobject_callfunction(test1,i,s,2,e); /調(diào)用python相應(yīng)的函數(shù) py_finalize(); /結(jié)束 c語言的示例代碼 #include python2.7/python.h int main() pyobject * g_pmodule = null; py_initialize(); /用法python之前,要調(diào)用py_initi
4、alize();這個函數(shù)進行初始化 if (!py_isinitialized() printf(init errorn); return -1; pyrun_simplestring(import sys); pyrun_simplestring(sys.path.append(./); g_pmodule =pyimport_importmodule(mytest);/這里是要調(diào)用的文件名,我們這里是當前名目下test.py if (!g_pmodule) printf(cant open python file!n); return -2; pyobject * test1 = pyob
5、ject_getattrstring(g_pmodule,test1);/這里是要調(diào)用的函數(shù)名 pyobject *objresult = pyobject_callfunction(test1,i,s,2,e);/調(diào)用函數(shù) if (!objresult) printf(invoke function failn); pyobject * test2= pyobject_getattrstring(g_pmodule,test2);/這里是要調(diào)用的函數(shù)名 objresult = pyobject_callfunction(test2,i,2);/調(diào)用函數(shù) char * x = pystring
6、_asstring(objresult); printf(%sn,x); py_finalize();/調(diào)用py_finalize,這個跟py_initialize相對應(yīng)的。 python程序mytest.py def test1(s,str): print s+str return 0 def test2(s): return s c程序的編譯方法 #假設(shè)我們的python編譯的時候安裝在/opt/python里,那么我們可以用這樣的指令來編譯程序 $gcc -i/opt/python/include -l/opt/python/lib/ -lpython2.7 test.c 留意: 這里要求python
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年數(shù)字精密壓力表合作協(xié)議書
- 四年級上冊口算
- 數(shù)學二年級口算加減乘除2000題
- 2024-2025學年度八年級物理上冊4.3平面鏡成像練習新版新人教版
- 西安交通大學城市學院《連鎖經(jīng)營調(diào)研實訓》2023-2024學年第二學期期末試卷
- 關(guān)于家長工作要點計劃月歷表(31篇)
- 華中科技大學《基礎(chǔ)生物學一》2023-2024學年第二學期期末試卷
- 石家莊科技信息職業(yè)學院《現(xiàn)代電子測量與應(yīng)用》2023-2024學年第二學期期末試卷
- 江蘇財經(jīng)職業(yè)技術(shù)學院《遙感科學與技術(shù)專業(yè)外語》2023-2024學年第二學期期末試卷
- 鄭州經(jīng)貿(mào)學院《趣說化學》2023-2024學年第二學期期末試卷
- (2024年)肺栓塞的護理課件
- 小學數(shù)學三年級下冊第八單元《數(shù)學廣角-搭配(二)》大單元集體備課整體設(shè)計
- (高清版)TDT 1031.6-2011 土地復墾方案編制規(guī)程 第6部分:建設(shè)項目
- 2024年江蘇省高中學業(yè)水平測試生物試卷
- 露天采場危險有害因素辨識
- 蘇教版一年級上、下冊勞動與技術(shù)教案
- 七上-動點、動角問題12道好題-解析
- 山東曲阜的孔廟之旅
- 一到六年級語文詞語表人教版
- 中煤集團綜合管理信息系統(tǒng)運維服務(wù)解決方案-V3.0
- 直播營銷與運營(第2版)全套教學課件
評論
0/150
提交評論