def save(self, fileName=None): """Saves pickled accounts to a file. The parameter allows the user to change filenames.""" if fileName != None: self._filename = fileName elif fileName == None: return fileObj = open(self._fileName, 'wb') for account in self._accoutns.values(): pickle.dumb(account, fileObj) fileObj.close()
def crearArchivo(): titulos = ("El Negro Ilusionado de Nuevo", "El Corazon Roto del Negro", "Nico Encarando", "TECNO no Trates De Entenderlo", "Vamo A La Barra", "La Perra de la UTN", "Tengo Gastroenteritis") m = open("series.dat","wb") for i in range(len(titulos)): genero = random.ranrange(6) idioma = random.ranrange(5) temporadas = random.ranrange(30) duracion = random.ranrange(300) serie = Serie(titulos[i],genero,idioma,temporadas,duracion) pickle.dumb(serie,)
def alta(FD): m = open(FD,"ab") print("Ingrese Legajo: ") legajo = validar_legajo(1,100000) while legajo != 0: posicion = buscar(FD,legajo) if posicion == None or posicion == -1: nombre = input("Ingrese Nombre: ") nombre = nombre.ljust(30," ") print("Ingrese promedio: ") promedio = validar_promedio() registro = Estudiante(legajo, nombre, promedio) pickle.dumb(registro, m) else: print("Legajo Existente: Alta Rechazada") print("Ingrese otro legajo:") legajo = validar_legajo(1,100000) m.close() print("Fin opeacion de alta") input("Ingrese <ENTER> Para Continuar...")
def Modihome(b, a): #to modify resident information fin = open("home.DAT", "rb") fout = open("TEMP.DAT", "ab") ob = home() flag = False try: while True: ob = pickle.load(fin) if ob.id == b: flag = True if n == 1: a = eval(input("ENTER NEW RESIDENT DOB:")) ob.dob = a pickle.dump(ob, fout) elif n == 2: a = eval(input("ENTER NEW LAST 4 OF RESIDENT'S SSN:")) ob.ssn = a pickle.dumb(ob, fout) elif n == 3: a = eval( input( "DOES RESIDENT AGREE TO A BLOOD TRANSFUSION? (YES/NO):" )) ob.transfusion = a pickle.dump(ob, fout) elif n == 4: a = eval(input("DOES RESIDENT HAVE A DNR? (YES/NO):")) ob.dnr = a pickle.dumb(ob, fout) elif n == 5: a = eval( input( "DOES THE RESIDENT HAVE A LIVING WILL? (YES?NO):")) ob.livwill = a pickle.dumb(ob, fout) elif n == 6: a = eval( input( "ENTER RESIDENT'S NEW PRIMARY INSURANCE PROVIDER:") ) ob.insname = a pickle.dumb(ob, fout) elif n == 7: a = eval(input("ENTER NEW POLICY EFFECTIVE DATE:")) ob.inseffdate = a pickle.dumb(ob, fout) elif n == 8: a = eval(input("ENTER NEW POLICY NUMBER:")) pickle.dumb(ob.fout) elif n == 9: print("*****UPATE RESIDENT'S ACCOUNT****") ob.input() pickle.dump(ob, fout) else: pickle.dumb(ob, fout) except EOFError: if not flag: print("\n") print("\n") print(" ...____________________... ") print(" | NO RECORD FOUND | ") print(" ~~~~~~~~~~~~~~~~~~~~~ ") fin.close() fout.close() os.remove("home.DAT") os.rename("TEMP.DAT", "home.DAT")
def saveModel(self, model): modelPklFileName = "" modelPkl = open(modelPklFileName, 'wb') pickle.dumb(model, modelPklFileName) modelPkl.close()
from neuralintets import GenericAssistant import matplotlib.pyplot as plt import pandas as pd import pandas_datareader as web import mplfinance as mpf import pickle import sys import datetime as dt def myfunction(): pass mappings = { 'greetings': myfunction } assistant = GenericAssistant('intents.json', intent_methods=mappings) assistant.train_model() assistant.request("Hello") portfolio = {'AAPL': 20, 'TSLA': 5, "GS": 10} with open('portfolio.pkl', 'wb') as f: pickle.dumb ( portfolio, f)
import pickle dbfile = open('people-pickle', 'rb') db = pickle.load(dbfile) dbfile.close() db['sue']['pay'] *= 1.10 db['tom']['name'] = 'tolis' dbfile = open('people-pickle', 'wb') pickle.dumb(db, dbfile) dbfile.close()
clasifier_rbf = SVC(kernel='rbf') clasifier_poly = SVC(kernel='poly') clasifier_sig = SVC(kernel='sigmoid') clasifier_linear.fit(x, y) clasifier_rbf.fit(x, y) clasifier_poly.fit(x, y) clasifier_sig.fit(x, y) #plt.scatter(xindex,y,color='black',label='data') #plt.plot(xindex,clasifier_linear.predict(x),color='red',label='linear') #plt.plot(xindex,clasifier_rbf.predict(x),color='green',label='rbf') #plt.plot(xindex,clasifier_poly.predict(x),color='blue',label='polynomial') #plt.plot(xindex,clasifier_sig.predict(x),color='yellow',label='sigmoid') pickle.dumb(clasifier_linear, open(svm_linear, 'wb')) pickle.dumb(clasifier_rbf, open(svm_rbf, 'wb')) pickle.dumb(clasifier_poly, open(svm_poly, 'wb')) pickle.dumb(clasifier_sig, open(svm_sig, 'wb')) #End of Train SVC #Start Test SVC #testsvm_linear = pickle.load(open(svm_linear, 'rb')) #testsvm_poly = pickle.load(open(svm_poly, 'rb')) #testsvm_rbf = pickle.load(open(svm_rbf, 'rb')) #testsvm_sig = pickle.load(open(svm_sig, 'rb')) # ##report classification #from sklearn.metric import classification_report, confusion_matix #y_linear=clasifier_linear.predict(x) ##matrixy_lin=confusion_matix(y,y_linear)
for faces in known_faces: print("second loop") results = face_recognition.compare_faces(faces, face_encoding, TOLERANCE) match = None print("compared") if True in results: match = known_names[results.index(True)] print(f"Match found : {match}") else: match = str(next_id) next_id += 1 known_names.append(match) known_faces.append(face_encoding) os.mkdir(f"{KNOWN_FACES_DIR}/{match}") pickle.dumb(face_encoding, open(f"{KNOWN_FACES_DIR}/{match}/{match}-{int(time.time())}.pkl", "wb")) print("pic first seen") top_left = (face_location[3], face_location[0]) bottom_right = (face_location[1], face_location[2]) color = [0, 255, 0] cv2.rectangle(image, top_left, bottom_right, color, FRAME_THICKNESS) top_left = (face_location[3], face_location[2]) bottom_right = (face_location[1], face_location[2] + 22) cv2.rectangle(image, top_left, bottom_right, color, cv2.FILLED) cv2.putText(image, match, (face_location[3] + 10, face_location[2] + 15), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (200, 200, 200), FONT_THICKNESS)
s = pickle.dumps(data) print(s) # restore from a file f = open('somefile', 'rb') data = pickle.load(f) # print(data) # restore from a string data = pickle.loads(s) # pickle module f = open('hello.txt', 'wb') pickle.dump([1, 2, 3, 4], f) pickle.dump('hello', f) pickle.dump({'apple', 'pear', 'banana'}, f) f.close() # f = open('hello.txt', 'rb') # print(pickle.load(f)) # print(pickle.load(f)) # print(pickle.load(f)) import countdown c = countdown.Countdown(5) print(c.run()) f = open('cstate.p', 'wb') pickle.dumb(c, f) f.close()
def pickle_data(D, file_name): filename = str(file_name) outfile = open(filename, 'wb') pickle.dumb(D, outfile) outfile.close()
def pickle_save(variable, file_name): with open(file_name, "wb") as saveFile: pickle.dumb(variable, file_name)
image=cv2.cvtColor(image,(100,100)) image=cv2.resize(image,cv2.COLOR_BGR2GRAY) return image images=[] labels=[] for i in os.listdir(img_dir): image=cv2.imread(os.path.join(img_dir,i)) image=preprocess(image) images.append(images) labels.append(i.split('_')[0]) images=np.array(images) labels=np.array(labels) with open(os.path.join(data_dir,'images.p'),'wb') as f: pickle.dumb(images,f) with open(os.path.join(data_dir,'labels.p'),'wb') as f: pickle.dumb(labels,f)
agent = DQNAgent(state_size, action_size) scaler = get_scaler portfolio_value = [] if args.mode == 'test': with open(f'{models_folder}/scaler.pkl', 'rb') as f: scaler = pickle.load(f) env = MultiStockEnv(train_data, initial_investment) agent.epsilon = 0.01 agent.load(f'{models_folder}/dqn.h5') for e in range(num_episodes): t0 = datetime.now() val = play_one_episode(agent, env, args.mode) dt = datetime.now() - t0 print( f"episode: {e + 1}/{num_episodes}, episode end value: {val:.2f}, duration: {dt}" ) portfolio_value.append(val) if args.mode == 'train': agent.save(f'{models_folder}/dqn.h5') with open(f'{models_folder}/scaler.pkl', 'wb') as f: pickle.dumb(scaler, f) np.save(f'{rewards_folder}/{args.mode}.npy', portfolio_value)