Changeset e6e89c4 in sasview for src/sas/sascalc
- Timestamp:
- Sep 22, 2017 7:14:38 PM (7 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- f7d720f
- Parents:
- 5a6a84e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/cansas_reader.py
r574adc7 re6e89c4 630 630 else: 631 631 save_in = "current_datainfo" 632 exec("default_unit = self.{0}.{1}".format(save_in, unitname))632 default_unit = getattrchain(self, '.'.join((save_in, unitname))) 633 633 if (local_unit and default_unit 634 634 and local_unit.lower() != default_unit.lower() … … 636 636 if HAS_CONVERTER: 637 637 # Check local units - bad units raise KeyError 638 #print("loading", tagname, node_value, local_unit, default_unit) 638 639 data_conv_q = Converter(local_unit) 639 640 value_unit = default_unit … … 716 717 doc, _ = self._to_xml_doc(datainfo) 717 718 # Write the file 718 file_ref = open(filename, 'w ')719 file_ref = open(filename, 'wb') 719 720 if self.encoding is None: 720 721 self.encoding = "UTF-8" … … 1283 1284 if units is not None: 1284 1285 toks = variable.split('.') 1285 exec("local_unit = storage.%s_unit" % toks[0]) 1286 # TODO: why split() when accessing unit, but not when setting value? 1287 local_unit = getattr(storage, toks[0]+"_unit") 1286 1288 if local_unit is not None and units.lower() != local_unit.lower(): 1287 1289 if HAS_CONVERTER == True: 1288 1290 try: 1289 1291 conv = Converter(units) 1290 exec("storage.%s = %g" % 1291 - (variable, conv(value, units=local_unit))) 1292 setattrchain(storage, variable, conv(value, units=local_unit)) 1292 1293 except Exception: 1293 1294 _, exc_value, _ = sys.exc_info() … … 1310 1311 raise ValueError(err_mess) 1311 1312 else: 1312 exec("storage.%s = value" % variable)1313 setattrchain(storage, variable, value) 1313 1314 else: 1314 exec("storage.%s = value" % variable)1315 setattrchain(storage, variable, value) 1315 1316 1316 1317 # DO NOT REMOVE - used in saving and loading panel states. … … 1375 1376 return True 1376 1377 return False 1378 1379 def getattrchain(obj, chain, default=None): 1380 """Like getattr, but the attr may contain multiple parts separated by '.'""" 1381 for part in chain.split('.'): 1382 if hasattr(obj, part): 1383 obj = getattr(obj, part, None) 1384 else: 1385 return default 1386 return obj 1387 1388 def setattrchain(obj, chain, value): 1389 """Like setattr, but the attr may contain multiple parts separated by '.'""" 1390 parts = list(chain.split('.')) 1391 for part in parts[-1]: 1392 obj = getattr(obj, part, None) 1393 if obj is None: 1394 raise ValueError("missing parent object "+part) 1395 setattr(obj, value)
Note: See TracChangeset
for help on using the changeset viewer.