pickle_idea.py: Make funciton unfamiliar() more robust #181
			
				
			
		
		
		
	|  | @ -6,6 +6,7 @@ | |||
| # Purpose: dictionary & pickle as a simple means of database. | ||||
| # Task: incorporate the functions into wordfreqCMD.py such that it will also show cumulative frequency. | ||||
| 
 | ||||
| import os | ||||
| import pickle | ||||
| from datetime import datetime | ||||
| 
 | ||||
|  | @ -55,10 +56,12 @@ def save_frequency_to_pickle(d, pickle_fname): | |||
|     f.close() | ||||
| 
 | ||||
| def unfamiliar(path,word): | ||||
|     f = open(path,"rb") | ||||
|     if not os.path.exists(path): | ||||
|         return None | ||||
|     with open(path,"rb") as f: | ||||
|         dic = pickle.load(f) | ||||
|         dic[word] += [datetime.now().strftime('%Y%m%d%H%M')] | ||||
|     fp = open(path,"wb") | ||||
|     with open(path,"wb") as fp: | ||||
|         pickle.dump(dic,fp) | ||||
| 
 | ||||
| def familiar(path,word): | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue