使用 os.path.split() 分離路徑及檔名
# === code begin ===
import os
mypath = 'c:\basedir\dirlevel1\dirlevel2\myfile.txt'
basedir, myfilename= os.path.split(mypath)
print basedir, myfilename
# === code end ===
>> c:\basedir\dirlevel1\dirlevel2 myfile.txt
星期四, 8月 27, 2009
在 python 程式中呼叫另一個 python 程式
使用 os.system() 來達成
prog1.py:
# ========= code below ===
print 'this is prog1.py'
# ========= code above ===
prog2.py
# === code below ===
import os
cmd = 'python prog1.py'
os.system(cmd)
# === code above ===
prog1.py:
# ========= code below ===
print 'this is prog1.py'
# ========= code above ===
prog2.py
# === code below ===
import os
cmd = 'python prog1.py'
os.system(cmd)
# === code above ===
星期三, 8月 05, 2009
How to transfer tuple to list
tuple 無法修改, 要修改其中的 element 就要使用 list. 把 tuple 轉為 list:
a = (1,2,3)
al = list(a)
就這麼簡單...
a = (1,2,3)
al = list(a)
就這麼簡單...
訂閱:
文章 (Atom)