def save_game(self): path = QFileDialog.getSaveFileName(self, 'Create save file', QDir.currentPath() + '/sav')[0] if path != '': save(path, self.play_widget.game, self.play_widget.export_log(), self.play_widget.move_count) self.statusbar.showMessage('Game saved', 5000)
def file_save_as(self): filename = QtWidgets.QFileDialog.getSaveFileName(self, 'Save File', os.getcwd()) filesave=QtCore.QFile(filename[0]) if filesave.open(QtCore.QIODevice.WriteOnly)==None : print("filesave.open(QtCore.QIODevice.WriteOnly)==None") return -1 else : items=[self.scene.lines, self.scene.rects, self.scene.ellipses, self.scene.texts, self.scene.polygons] save(items, str(filename[0])) self.statusbar.showMessage('File saved')
def updatebonds(accounts): global total_bond_worth_issued save_load.save(accounts) try: for item in accounts: item = accounts[item] for bond in item.bonds: bond = item.bonds[bond] total_bond_worth_issued -= bond.update() except: pass
def dft_teacher(layers, recursive=False): dft_data = pd.read_csv('../input/DFT_samples.csv') dft_X = dft_data.drop(columns=['Label']) dft_Y = dft_data.Label.values clf = teach_nn(dft_X.values, dft_Y, layers, recursive) model_name = 'mlpc_' for chunk in layers: model_name = model_name + '_' + str(chunk) save(clf, model_name, 'mlpc') return clf
def mkquote(prefix,influx,sender,debug): arg = influx[10+len(prefix):] if debug: print sender+":"+prefix+"makequote "+str(len(arg))+" Characters" if len(arg) == 0: return("Type something to a quote") else: files = listdir(directory+"userquotes") numb = 0 while True: numb += 1 if sender.lower()+str(numb) in files: pass else: save(directory+"userquotes/"+sender.lower()+str(numb),[arg,sender.lower()]) return("Saved as:"+sender.lower()+str(numb)) break
def mkquote(prefix, influx, sender, debug): arg = influx[10 + len(prefix):] if debug: print sender + ":" + prefix + "makequote " + str( len(arg)) + " Characters" if len(arg) == 0: return ("Type something to a quote") else: files = listdir(directory + "userquotes") numb = 0 while True: numb += 1 if sender.lower() + str(numb) in files: pass else: save(directory + "userquotes/" + sender.lower() + str(numb), [arg, sender.lower()]) return ("Saved as:" + sender.lower() + str(numb)) break
def updatebonds(accounts): global total_bond_worth_issued save_load.save(accounts) try: for item in accounts: item = accounts[item] total = 0 todelete = [] for bond in item.bonds: i = bond bond = item.bonds[bond] a, didpayout = bond.update() total += a if didpayout: todelete.append(i) for i in item.bonds.copy(): if i in todelete: print(f"deleted bond {i} from account {item.svid}") del item.bonds[i] if not total == 0: svapi.sendtransaction(total, os.getenv("Issuer-SVID"), item.svid) except: pass
from FMLformatter import formatter from urllib2 import urlopen try: from hashlib import md5 except: from md5 import md5 from save_load import save,load import CORE_DATA directory = CORE_DATA.directory FML = urlopen("http://www.fmylife.com/random") formatted = formatter(FML.read().split("\n")) for Quote in formatted: exact = Quote[:Quote.find("#")] # print exact save(directory+"fmlquotes/"+md5(exact).hexdigest()+".txt",exact)
def keyHandle(grid, pasy, pasx,next_lev,call): #pasy and pasx = spot to win #'call' does not do anything right now while True: if me.hp<=0: break i = input('\nAction: ') if i == 'w' or i == 'W': me.y+=yp try: print('You walk forward and see '+grid[me.y][me.x].pview, end='') except: me.y+=ym print("Bonk! You can't go that way.") elif i == 's' or i == 'S': me.y+=ym try: if me.y>=0: print('You take a few steps backward and turn around. You see '+grid[me.y][me.x].pview, end='') else: me.y+=yp print("Bonk! You can't go that way!") except: me.y+=yp print("Bonk! You can't go that way.") elif i == 'd' or i == 'D': me.x+=1 try: print('You walk to the rightmost room and see '+grid[me.y][me.x].pview, end='') except: me.x-=1 print("Bonk! You can't go that way.") elif i == 'a' or i == 'A': me.x-=1 try: if me.x>=0: print('You turn around and walk to the left. In front of you, you see '+grid[me.y][me.x].pview, end='') else: me.x+=1 print("Bonk! You can't go that way.") except: me.x+=1 print("Bonk! You can't go that way.") ############ elif i == 'hp' or i == 'HP': me.printHP() elif i == 'h' or i == 'H': print(helplist) elif i == 'i' or i == 'I': me.printInvent() elif i == 'p' or i == 'P': i = input('Welcome to the Player Editor!\nWhat would you like to change? (w = weapon, n = name) ') if i == 'w': ct = 0 for tp in range(0, len(me.invent)): if me.invent[tp].name in weaponlist: print(str(tp)+') '+me.invent[tp].name) ct += 1 if ct == 0: print('Sorry, you have no weapons in your inventory to choose from.') else: try: i = input('Type weapon number: ') old_weap = me.weapon me.weapon = me.invent[int(i)] del me.invent[int(i)] me.invent.append(old_weap) print('Weapon Changed!') except: print("That's not a number.") elif i == 'n': i = input('Type your name: ') me.name = i print('Name Changed!') print('You: \n\nName: '+me.name+'\nHP: '+str(me.hp)+'\nWeapon: '+me.weapon.name) elif i == 'xy': print('\nX: '+str(me.x)+'\nY: '+str(me.y)) elif i == 'wallet': print(str(me.wallet)+' Gold') elif i == 'quit': try: i = input("Save first? (Y/n) ") if i == 'Y' or i == 'y': sl.save('saves/save1.txt','saves/save1inv.txt',me,village) sys.exit() except: print("Save/Load not available") sys.exit() elif i == 'map': mapg(grid) else: print('Huh?') ############ if grid[me.y][me.x].name in enemylist:#!= 'bspace': if musc == True: m_chan.pause() s_chan.play(seffect2) me.hp = atthandle(grid,me.x,me.y,me) s_chan.stop() m_chan.unpause() else: me.hp = atthandle(grid,me.x,me.y,me) elif grid[me.y][me.x].name in itemlist: inp = input(' Pick up? (Y/n) ') if inp == 'Y' or inp == 'y': if grid[me.y][me.x].name != 'Gold': me.invent.append(grid[me.y][me.x]) else: me.wallet += grid[me.y][me.x].amt grid[me.y][me.x] = bspace5(me.x,me.y) print('Item added to inventory') elif grid[me.y][me.x].name in interlist: me.wallet = grid[me.y][me.x].act(me) elif grid[me.y][me.x].name == 'level': print("") print("-"*80) if grid[me.y][me.x].num == 1 and grid[me.y][me.x].locked == False: Adventure1(0,0,True) elif grid[me.y][me.x].num == 2 and grid[me.y][me.x].locked == False: Adventure2(0,0,True) elif grid[me.y][me.x].num == 3 and grid[me.y][me.x].locked == False: Adventure3(0,0,True) elif grid[me.y][me.x].num == 4 and grid[me.y][me.x].locked == False: Adventure4(0,0,True) else: print("That level is locked") #add more for more levels #music if musc == True and m_chan.get_busy() == False: randnum = random.randint(0,11) m_chan.play(playlist[randnum]) if me.x == pasx and me.y == pasy: print('') print("-"*80) me.hp = 100 me.x = 0 me.y = 0 if next_lev == 2: village[5][1].locked = False elif next_lev == 3: village[5][2].locked = False elif next_lev == 4: village[5][3].locked = False#add more for more levels print("LEVEL BEAT! NEXT LEVEL UNLOCKED!") print("-"*80) i = input('Continue story? (Y/n) ') if i == 'Y' or i == 'y': if next_lev == 2: Adventure2(0,0,True) elif next_lev == 3: Adventure3(0,0,True) elif next_lev == 4: Adventure4(0,0,True) elif next_lev == 5: Adventure2(0,0,True) elif next_lev == 6: Adventure2(0,0,True) elif next_lev == 7: Adventure2(0,0,True) else: print('In the Village') Village()
# Print model summary print_model_summary(model) # Train model tbCallBack = TensorBoard(log_dir=outfolder, histogram_freq=0, write_graph=True, write_images=True) model.fit(x_train, y_train, validation_split=0.2, epochs=25, batch_size=250, callbacks=[tbCallBack]) save(model, path=outfolder) # Evaluate model scores = evaluate_model(model, x_test, y_test) # Print scores print('\n\n') print("Loss: ", backend.get_value(scores[0])) print("Accuracy: ", backend.get_value(scores[1]) * 100, "%") # # Create model and print to log file # model = tanh_model() # # model = relu_model() # print_model_summary(model) # # Train model
optimizer.zero_grad() output = model.forward(flower_images) loss = criterion(output, labels) loss.backward() optimizer.step() running_loss += loss.item() if steps % print_every == 0: # Set model to evaluation mode, cancels the dropout to make sure the network is tested. model.eval() # Make sure the Tensor is not tracking operations on itself, to save memory. with torch.no_grad(): valid_loss, accuracy = validation(model, validloader, criterion) print( "Epoch: {}/{}".format(e + 1, epochs), "Training Loss: {}".format(running_loss / print_every), "Validation Loss: {}".format(valid_loss / len(validloader)), "Validation Accuracy: {:.3f}".format(accuracy / len(validloader))) running_loss = 0 model.train() print("Time Elapsed for epoch: {:.3f} seconds".format(time.time() - start)) # saves the model to the specified directory, if none specified it defaults to checkpoint.pth save_load.save(options.arch, model, options.save_dir)