PIXNET Logo登入

KwCheng's blog

跳到主文

Blog for Computer Science ...

部落格全站分類:圖文創作

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 10月 06 週一 201417:25
  • python - time

Reference

Introduction to datetime object

(繼續閱讀...)
文章標籤

JerryCheng 發表在 痞客邦 留言(0) 人氣(22)

  • 個人分類:Python
▲top
  • 9月 16 週二 201417:39
  • python - thread

Return Value of threads
# -*- coding: UTF-8 -*-
def foo(bar, result, index):
print 'hello {0}'.format(bar)
result[index] = "foo"

from threading import Thread

threads = [None] * 10
results = [None] * 10

for i in range(len(threads)):
threads[i] = Thread(target=foo, args=('world!', results, i))
threads[i].start()

# do some other stuff

for i in range(len(threads)):
threads[i].join()

print " ".join(results) # what sound does a metasyntactic locomotive make?
(繼續閱讀...)
文章標籤

JerryCheng 發表在 痞客邦 留言(0) 人氣(75)

  • 個人分類:Python
▲top
  • 4月 14 週一 201416:31
  • python - inheritance & template pattern

class base:
def __init__(self, name):
self.name = name

def show(self):
print "Base Class is here!!"

def show_name(self):
print "name:", self.name

def process(self):
self.show_name()
self.show()

class sub(base):
def show(self): // override show method
print "Sub class is here!!"

base_class = base("Base Class")
base_class.process()

sub_class = sub("Sub Class")
sub_class.process()

(繼續閱讀...)
文章標籤

JerryCheng 發表在 痞客邦 留言(0) 人氣(10)

  • 個人分類:Python
▲top
  • 4月 08 週二 201418:03
  • sorting by value of dictionary

d = {1: 2, 3: 4, 4:3, 2:1, 0:0}
sorted(d.items(), key=lambda x: x[1])
(繼續閱讀...)
文章標籤

JerryCheng 發表在 痞客邦 留言(0) 人氣(1)

  • 個人分類:Python
▲top
  • 4月 07 週一 201414:27
  • python - thread example

# -*- coding: UTF-8 -*-


import time
import threading


def myfunc(i):
time.sleep(5)
print "finished sleeping from thread %d"%(i)


def main():
for i in range(10):
t = threading.Thread(target = myfunc , args=(i,))
time.sleep(1)
t.start()
print t.name


if __name__ == '__main__':
main()

(繼續閱讀...)
文章標籤

JerryCheng 發表在 痞客邦 留言(0) 人氣(62)

  • 個人分類:Python
▲top
  • 4月 07 週一 201414:23
  • python - time

import time
import datetime

def interval_secs(time_start , time_end):
diff = time_end - time_start
return diff.seconds + diff.days * 24 * 60 * 60

time_start = datetime.datetime.now().strftime("%y-%m-%d-%H-%M-%S")
time_start = datetime.datetime.strptime(time_start , "%y-%m-%d-%H-%M-%S")
print time_start
time.sleep(3)
time_end = datetime.datetime.now()
print interval_secs(time_start , time_end)
(繼續閱讀...)
文章標籤

JerryCheng 發表在 痞客邦 留言(0) 人氣(14)

  • 個人分類:Python
▲top
  • 10月 17 週三 201216:50
  • python - command line arguments

在python中 , 若要像c一樣傳入command line的arguments , 
可以藉由sys.argv的方式來取得argument的value:
import sys

for arg in sys.argv:
(繼續閱讀...)
文章標籤

JerryCheng 發表在 痞客邦 留言(0) 人氣(816)

  • 個人分類:Python
▲top
  • 10月 17 週三 201213:48
  • python - splitlines()

在python中 , 我們若要將輸入的內容一行行的讀取 , 
可以使用splitlines()這個method , 
for example :
infors=str(execSystemCmd('cat /etc/hosts')).splitlines()
(繼續閱讀...)
文章標籤

JerryCheng 發表在 痞客邦 留言(0) 人氣(41)

  • 個人分類:Python
▲top
  • 10月 17 週三 201213:35
  • python - strip()

在python中 , 我們可以藉由strip()來去掉字串頭尾的空白,
for example:
def execSystemCmd(cmd):
proc = subprocess.Popen([cmd],shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
(繼續閱讀...)
文章標籤

JerryCheng 發表在 痞客邦 留言(0) 人氣(367)

  • 個人分類:Python
▲top
1

個人資訊

JerryCheng
暱稱:
JerryCheng
分類:
圖文創作
好友:
累積中
地區:

熱門文章

  • (126)Matlab - 內建變數
  • (9,406)notepad++ - 使用notepad++對文字進行轉碼
  • (444)Mathematics - 判斷point是否在triangle內
  • (34,773)Cpp - ifstream (read file) - 開檔 & 讀檔
  • (66)Solaris - svcs command

文章分類

toggle Software (5)
  • Notepad++ (1)
  • Graphviz (0)
  • Windows (1)
  • Eclipse (8)
  • Sloaris (5)
toggle Programming (11)
  • my_c_lib (7)
  • Shell programming (12)
  • C / Cpp (75)
  • Python (9)
  • Html/CSS (2)
  • JavaScript (18)
  • JSP (4)
  • Matlab (13)
  • PHP (1)
  • SQL (7)
  • Java (59)
toggle Information Retrieval (2)
  • Information Retrieval (7)
  • IR - Lemur (2)
  • Solaris (3)
  • Mathematics (4)
  • computer science (4)
  • Linux (17)
  • Statistics (1)
  • 未分類文章 (1)

最新文章

  • python - time
  • python - thread
  • Javascript - class
  • shell - while loop
  • expect - sftp example
  • javascript injection
  • [轉錄] ls color setting
  • python - inheritance & template pattern
  • sorting by value of dictionary
  • Browse all elements of array

動態訂閱

文章精選

文章搜尋

誰來我家

參觀人氣

  • 本日人氣:
  • 累積人氣: