Advertisement
jevixlugya

save to json

Jul 18th, 2023
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1.     def save_to_favourite(self):
  2.         print('added')
  3.         app = MDApp.get_running_app()
  4.         self.image=app.root.get_screen('buyscreen').ids.product_image2.source        
  5.         self.name=app.root.get_screen('buyscreen').ids.product_name2.text
  6.         self.price=app.root.get_screen('buyscreen').ids.product_price2.text
  7.         self.desc=app.root.get_screen('buyscreen').ids.product_description2.text
  8.         self.contact=app.root.get_screen('buyscreen').ids.product_contact2.text
  9.         self.location=app.root.get_screen('buyscreen').ids.product_location2.text
  10.  
  11.         dict1 = {'1':{'name': self.name, 'price': self.price, "image": self.image,'description':self.desc,'contact':self.contact,'location':self.location}}
  12.         with open(self.p, 'w') as f:
  13.             #     f.write(json.dumps(dict1, indent=4))
  14.             json.dump(dict1, f, indent=4)
  15.         from pprint import pprint
  16.         dict2 = {'3':{'name': self.name, 'price': self.price, "image": self.image,'description':self.desc,'contact':self.contact,'location':self.location}}  
  17.         if self.p.exists():
  18.             dict1.update(dict2)
  19.             pprint(dict2)
  20.             with open(self.p, 'w') as f:
  21.                 json.dump(dict1, f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement