def add_ctrl(self, grid, panel): # 添加表格 for i in range(var.row * var.column): MyClass.cellList.append(MyClass.cell(panel, i)) 行号 = i // var.column 列号 = i % var.column MyClass.cellList[i].box = wx.StaticText(panel, label=str(i + 1), size=var.size) grid.Add(MyClass.cellList[i].box, pos=(行号 + 3, 列号), border=10)
def main(): # making an object obj = MyClass('teguh', 22) obj_2 = MyClass('satya', 21) # printing object attribute print(obj.name, obj.age, obj_2.name, obj_2.age) # modifying attribute obj_2.name = 'Dharma' print(obj.name, obj.age, obj_2.name, obj_2.age) # accessing methods print(obj.get_description()) print(obj.speak('why so lonely')) print(obj.__str__()) # inheritance obj_3 = InheritClass('dog', 2) print(obj_3.__str__()) print(obj_3.speak())
import sys, MyClass from PyQt5.QtWidgets import QApplication # 导入相应的包 if __name__ == '__main__': app = QApplication(sys.argv) w = MyClass.MyClass() sys.exit(app.exec_())
import MyClass SamuelRecord = MyClass.MyClass() AnnieRecord = MyClass.MyClass("Annie", 44) print(SamuelRecord.GetAge()) SamuelRecord.SetAge(33) print(AnnieRecord.GetName()) AnnieRecord.SetName("Sophie") print(SamuelRecord) print(AnnieRecord)
import MyClass MyClass.hello_world("Spam")
print("-------------------------------") print(" My First Class") print("-------------------------------") print("\n") x = float() y = float() print("Set the real and imagined parts!") print("Real part: ") x = input() print("Imagined part: ") y = input() print("\n") #Object = MyClass.Complex() #Object = MyClass.Complex(-3.1, 2.5) Object = MyClass.Complex(x, y) #print(Object.re) #print(Object.im) ################################ Object_Function = Object.foo() print(Object_Function) ################################ Object_Function = Object.Get_Real_Part() print("Real part: ", Object_Function) ################################ Object_Function = Object.Get_Imagined_Part() print("Imagined part: ", Object_Function) ################################ print("\n") #Add_To_Array = Object.Add_To_Array()
import MyClass SamsRecord = MyClass.MyClass() AmysRecord = MyClass.MyClass("Amy", 44) print(SamsRecord.GetAge()) SamsRecord.SetAge(33) print(AmysRecord.GetName()) AmysRecord.SetName("Aimee") print(SamsRecord) print(AmysRecord)
def test_myclass() -> None: classy = MyClass("classy") assert classy.name == "classy"
print('loading existing data...') with open('train_data.pkl', 'rb') as fr: train_data = pickle.load(fr) with open('test_data.pkl', 'rb') as fr: test_data = pickle.load(fr) test_size = len(test_data) vocab_path = os.path.join('.', args.train_data, 'word2id.pkl') tag_path = os.path.join('.', args.train_data, 'tag2id.pkl') id2tag_path = os.path.join('.', args.train_data, 'id2tag.pkl') if not os.path.exists(vocab_path): MyData.vocab_build(vocab_path, tag_path, id2tag_path, train_data, 5) cn2id, en2id, id2en = MyData.read_dictionary(vocab_path, tag_path, id2tag_path) if args.mode == 'train': print('start training...') encoder1 = MyClass.EncoderRNN(len(cn2id), args.embedding_size, args.hidden_size).to(device) attn_decoder1 = MyClass.AttnDecoderRNN(args.hidden_size, len(en2id), dropout_p=0.1).to(device) trainIters(encoder1, attn_decoder1, train_data, args.epoch_num, print_every=64) #75000:训练预料条数 5000:每5000次输出一次损失情况 torch.save(encoder1, 'model/encoder.pkl') torch.save(attn_decoder1, 'model/decoder.pkl') else: encoder = torch.load('model/encoder.pkl') decoder = torch.load('model/decoder.pkl') evaluateTest(encoder, decoder, test_data, cn2id, id2en)
#from MyClass import Student import MyClass s = MyClass.Student('Heim', 20) s.sayHi()
def test_subTogether(self): self.assertEqual(MyClass.subNumbers(62, 17), 45)
def test_addTogether(self): self.assertEqual(MyClass.addNumbers(45, 17), 62)
import MyClass # from MyClass import User # I could have done this, so I don't have to type 'MyClass.User() everytime' # if I had instanciated MyClass, I could do user1 = User('Lucas', 'Costa') user1 = MyClass.User('Lucas', 'Costa') user2 = MyClass.User('Jeff', 'Lname') print user1.getName() user1.test() # createUser(b)
def test_calc_square(self): result = MyClass.calc_square(10, 10, 10) self.assertTrue(result > 40, 'Error result')
import MyClass myCar1 = MyClass.car() print(myCar1.getColor())