from wsgiref.simple_server import make_server
def hello_world_app(environ, start_response):
start_response('200 OK', [('Content-type', 'text/html; charset=utf-8')] )
return [b'Welcome To The Python Web Server !!']
httpd = make_server('', 80, hello_world_app)
print("Server is Start ... ")
httpd.serve_forever()
黃彥霖 發表在 痞客邦 留言(0) 人氣(912)
變數名稱前有兩條底線就成為 私有 (Private) 變數
class Test ():
__a = 0 # 私有變數
b = 0 # 公開變數
def setA(self,a):
Test.__a=a
def getA(self):
return Test.__a
t = Test()
t.setA(99)
print(t.getA()) # 從公開方法(函數)取得私有變數為合法程式
# print(t.__a) # 直接取得私有變數為錯誤程式
黃彥霖 發表在 痞客邦 留言(0) 人氣(903)
無建構子版本:
import threading, time
class MyClass (threading.Thread): # 繼承 Thread 類別
def run(self): # 覆載 (Override) Thread 類別的方法(函數)
for i in range(5): # 迴圈執行五次
print('ok') # 輸出 ok
time.sleep(1) # 暫停一秒,如果要暫停 0.1秒可寫成 time.seep(0.1)
MyClass().start() # 啟動執行緒
黃彥霖 發表在 痞客邦 留言(1) 人氣(10,821)
在Netbeans [工具→外掛→設定→加入] 中添加此網址: http://deadlock.netbeans.org/hudson/job/nbms-and-javadoc/lastStableBuild/artifact/nbbuild/nbms/updates.xml.gz
之後在到 [可用的外掛程式] 安裝即可
黃彥霖 發表在 痞客邦 留言(0) 人氣(949)
class MyClass:
def setName(n, name):
n.name = name
def getName(n):
return n.name
m = MyClass()
m.setName('黃彥霖')
print(m.getName())
黃彥霖 發表在 痞客邦 留言(0) 人氣(1,015)
def big(a, b):
if a>b :
return a
else :
return b
print(big(3,5))
print(big(5,3))
print(big('AAA','BBB'))
黃彥霖 發表在 痞客邦 留言(0) 人氣(299)
for i in range(5) :
print('ok ', end='')
執行結果:ok ok ok ok ok
黃彥霖 發表在 痞客邦 留言(0) 人氣(5,432)
# 寫檔案+創建檔案:
f = open('A.txt', 'w', encoding = 'UTF-8') # 也可使用指定路徑等方式,如: C:\A.txt
f.write('你好1\n')
f.write('你好2\n')
f.write('你好3\n')
f.close()
# 讀檔案 1:
f = open('A.txt', 'r', encoding = 'UTF-8')
while True :
i = f.readline()
if i=='': break
print(i,end='')
f.close()
# 讀檔案 2:
for i in open('A.txt', 'r', encoding='UTF-8'):
print(i,end='')
黃彥霖 發表在 痞客邦 留言(0) 人氣(52,476)
name = input('請輸入你的名子:')
print ('你的名子是:' + name)
黃彥霖 發表在 痞客邦 留言(0) 人氣(2,633)
a = 100 # 將整數 100 指派給 a 變數
b = 3.14 # 將浮點數 3.14 指派給 b 變數
c = "Hello" # 將字串 Hello 指派給 c 變數
d = 'Hi' # 將字串 Hi 指派給 d 變數
print (a)
print (b)
print (c)
print (d)
黃彥霖 發表在 痞客邦 留言(0) 人氣(461)