funs = []
for c in range(3):
a = lambda x: x + c
funs.append(a)
wsunccake 發表在 痞客邦 留言(0) 人氣(5)

先在 project1 目錄下建立 Person.py 和 test1.py 兩個檔案, 內容如下
Person.py
class Person(object):
def __init__(self, name):
self.setName(name)
wsunccake 發表在 痞客邦 留言(0) 人氣(125)
執行 PyCharm
PyCharm 的開始畫面
當有建立過 project 後, PyCharm 的開始畫面
wsunccake 發表在 痞客邦 留言(0) 人氣(2,095)
import unittest # 載入unittest
class Person: # 要測試的class
def __init__(self, name):
self.name = name
self.age = 10
def getName(self):
return self.name
def setAge(self, age):
self.age = age
class TestPerson(unittest.TestCase):
def setUp(self): # 每個測試初始化
print 'init',
self.p = Person('John')
def test_getName(self): #要測試的功能, 名稱需test開頭
print 'test getNme',
self.assertEqual(self.p.getName(), 'John' )
def test_setAge(self):
print 'test setAge',
self.assertEqual(self.p.age, 10 )
self.p.setAge(18)
self.assertNotEqual(self.p.age, 10 )
def tearDown(self): # 每個測試結束
print 'final'
wsunccake 發表在 痞客邦 留言(0) 人氣(1,151)

import wx class HelloFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, "HelloFrame", size=(200, 100)) panel = wx.Panel(self, -1) #初始化frame wx.StaticText(panel, -1, "Hello World", pos=(60, 25)) #設定文字 if __name__ == '__main__': app = wx.PySimpleApp() #建立simple app frame = HelloFrame() #產生自訂frame frame.Show(True) #顯示frame app.MainLoop() #執行app
|
wsunccake 發表在 痞客邦 留言(0) 人氣(1,028)