def test_from_json_file(nested_example): """ can it be re-created from an actual json file? """ json_str = nested_example.to_json() with open("temp.json", 'w') as tempfile: tempfile.write(nested_example.to_json()) with open("temp.json") as tempfile: reconstructed = js.from_json(tempfile) reconstructed = js.from_json(json_str) assert reconstructed == nested_example
def json_load(): """Create an instance of Group and load into this a list of donors from a file written in json format.""" with open('json.txt', 'r') as from_file: from_dict = from_file.read() if from_dict == '': return else: return js.from_json(from_dict)
def test_from_json_dict2(nested_dict): """ can it be re-created from an actual json string? """ json_str = nested_dict.to_json() reconstructed = js.from_json(json_str) assert reconstructed == nested_dict
def load(self, filename="donor_db.json"): """Return a Donors class object reconstructed from a json file.""" try: with open(filename) as tempfile: reconstructed = js.from_json(tempfile) return reconstructed except IOError: return Donors([ SingleDonor(key, value) for key, value in { "Bill Murray": [125, 1.0], "Woody Harrelson": [71.5, 1.25], "Jesse Eisenberg": [99.99, 1.75] }.items() ])
def load_json_from_file(self): print("Loading from json") with open(self.data_file + ".json", 'r') as file_in: temp = js.from_json(file_in) self.donors_list = temp.donors_list return self.count
def load(): global collection with open("data_file.json") as data_file: collection = js.from_json(data_file)
def load_donors(self, reset=False): filename = 'donors_reset.json' if reset else 'donors.json' data = self.read_from_file(filename) dObj = js.from_json(data) self.donors = dObj
def load_from_json(self): target_directory = os.getcwd() target_file_path = os.path.join(target_directory, self.file_name) with open(target_file_path, 'r') as fp: donor_load = fp.read() return js.from_json(donor_load)
def load(self): with open("Donor_DB.json", "r") as db_file: self._donors = js.from_json(db_file)._donors
def load_from_file(cls, filename): with open(filename, 'r') as infile: obj = js.from_json(infile) print("\nfrom_json complete!") return obj