IHateMyselfx

Do nothing with Json's

Jul 23rd, 2022
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. import json
  2. import sys as q
  3.  
  4. def Json_file_read():
  5.    
  6.     file_name = input("(with the current state it must be in the same directory)\n.json file name:   ")
  7.    
  8.     with open(file_name, "r", encoding="utf-8") as our_opened_file:
  9.    
  10.        data_base = json.load(our_opened_file)
  11.        print(f"{file_name} Load Successful")
  12.  
  13.     if input("Wanna see the file? (y/n)") == "y" or "y".upper():
  14.         print(data_base)
  15.        
  16.     else:
  17.        
  18.         home_text()    
  19.  
  20.  
  21.  
  22. def Json_file_dump():
  23.    
  24.    
  25.     save_file_name = input("Save as: ")
  26.     value_numb = int(input("Give me the Value number \n: "))
  27.     i = 0
  28.     z = []
  29.     key = input("Give me the key name : ")
  30.     XO = {key:[]}
  31.     while i < value_numb:
  32.        
  33.         value = input(f"Give me the {i} Value name : ")
  34.         z.append(value)
  35.         XO[key].append(z)
  36.        
  37.         i += 1    
  38.     print(XO)
  39.     with open(save_file_name, "w", encoding="utf-8") as save_file:
  40.        
  41.         json.dump(XO, save_file, ensure_ascii=False, indent=2)
  42.         print("SAVE WAS SUCCESSFUL ")
  43.    
  44.     #data = json.dumps(data_base, ensure_ascii=False, indent=2)
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. def home_text():
  55.     print("\nIn this Python project you can do literally nothing with Json file's")
  56.     if input("1.) File Read\n2.) File Create ('JSON')\n3.) Quit\nWhat do you want: ") == "1":
  57.         Json_file_read()
  58.     elif "2":
  59.         Json_file_dump()
  60.  
  61.     else:
  62.         q.exit("BRO")
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. #Json_file_dump()
  74. home_text()
  75.  
Advertisement
Add Comment
Please, Sign In to add comment