72 """ |
72 """ |
73 Public method to get the attributes of a variable as a dictionary. |
73 Public method to get the attributes of a variable as a dictionary. |
74 |
74 |
75 @param var variable to be converted |
75 @param var variable to be converted |
76 @type any |
76 @type any |
77 @return dictionary containing the variable attributes |
77 @yield tuple containing the batch start index and a dictionary |
78 @rtype dict |
78 containing the variable attributes |
|
79 @ytype tuple of (int, dict) |
79 """ |
80 """ |
80 names = dir(var) |
81 names = dir(var) |
81 if not names and hasattr(var, "__members__"): |
82 if not names and hasattr(var, "__members__"): |
82 names = var.__members__ |
83 names = var.__members__ |
83 |
84 |
136 @return string representation of the given key |
137 @return string representation of the given key |
137 @rtype str |
138 @rtype str |
138 """ |
139 """ |
139 if isinstance(key, str): |
140 if isinstance(key, str): |
140 key = repr(key) |
141 key = repr(key) |
141 # Special handling for Python2 unicode strings and bytes object |
142 # Special handling for bytes object |
142 # Raw and f-Strings are always converted to (unicode) str |
143 # Raw and f-Strings are always converted to str |
143 if key[0] in 'ub': |
144 if key[0] == 'b': |
144 key = key[1:] |
145 key = key[1:] |
145 |
146 |
146 return key # __IGNORE_WARNING_M834__ |
147 return key # __IGNORE_WARNING_M834__ |
147 |
148 |
148 def getDictionary(self, var): |
149 def getDictionary(self, var): |
149 """ |
150 """ |
150 Public method to get the attributes of a variable as a dictionary. |
151 Public method to get the attributes of a variable as a dictionary. |
151 |
152 |
152 @param var variable to be converted |
153 @param var variable to be converted |
153 @type any |
154 @type any |
154 @return dictionary containing the variable attributes |
155 @yield tuple containing the batch start index and a dictionary |
155 @rtype dict |
156 containing the variable attributes |
|
157 @ytype tuple of (int, dict) |
156 """ |
158 """ |
157 d = {} |
159 d = {} |
158 start = count = 0 |
160 start = count = 0 |
159 allItems = list(var.items()) |
161 allItems = list(var.items()) |
160 try: |
162 try: |
214 """ |
216 """ |
215 Public method to get the attributes of a variable as a dictionary. |
217 Public method to get the attributes of a variable as a dictionary. |
216 |
218 |
217 @param var variable to be converted |
219 @param var variable to be converted |
218 @type any |
220 @type any |
219 @return dictionary containing the variable attributes |
221 @yield tuple containing the batch start index and a dictionary |
220 @rtype dict |
222 containing the variable attributes |
|
223 @ytype tuple of (int, dict) |
221 """ |
224 """ |
222 d = {} |
225 d = {} |
223 start = count = 0 |
226 start = count = 0 |
224 for idx, value in enumerate(var): |
227 for idx, value in enumerate(var): |
225 d[str(idx)] = value |
228 d[idx] = value |
226 count += 1 |
229 count += 1 |
227 if count >= BatchSize: |
230 if count >= BatchSize: |
228 yield start, d |
231 yield start, d |
229 start = idx + 1 |
232 start = idx + 1 |
230 count = 0 |
233 count = 0 |
402 """ |
406 """ |
403 Public method to get the attributes of a variable as a dictionary. |
407 Public method to get the attributes of a variable as a dictionary. |
404 |
408 |
405 @param var variable to be converted |
409 @param var variable to be converted |
406 @type any |
410 @type any |
407 @return dictionary containing the variable attributes |
411 @yield tuple containing the batch start index and a dictionary |
408 @rtype dict |
412 containing the variable attributes |
|
413 @ytype tuple of (int, dict) |
409 """ |
414 """ |
410 d = {} |
415 d = {} |
411 start = count = 0 |
416 start = count = 0 |
412 try: |
417 try: |
413 len(var) # Check if it's an unsized object, e.g. np.ndarray(()) |
418 len(var) # Check if it's an unsized object, e.g. np.ndarray(()) |
494 """ |
499 """ |
495 Public method to get the attributes of a variable as a dictionary. |
500 Public method to get the attributes of a variable as a dictionary. |
496 |
501 |
497 @param var variable to be converted |
502 @param var variable to be converted |
498 @type any |
503 @type any |
499 @return dictionary containing the variable attributes |
504 @yield tuple containing the batch start index and a dictionary |
500 @rtype dict |
505 containing the variable attributes |
|
506 @ytype tuple of (int, dict) |
501 """ |
507 """ |
502 d = {} |
508 d = {} |
503 start = count = 0 |
509 start = count = 0 |
504 allKeys = list(var.keys()) |
510 allKeys = list(var.keys()) |
505 try: |
511 try: |
577 """ |
583 """ |
578 Public method to get the attributes of a variable as a dictionary. |
584 Public method to get the attributes of a variable as a dictionary. |
579 |
585 |
580 @param var variable to be converted |
586 @param var variable to be converted |
581 @type any |
587 @type any |
582 @return dictionary containing the variable attributes |
588 @yield tuple containing the batch start index and a dictionary |
583 @rtype dict |
589 containing the variable attributes |
|
590 @ytype tuple of (int, dict) |
584 """ |
591 """ |
585 d = {} |
592 d = {} |
586 start = count = 0 |
593 start = count = 0 |
587 allItems = var.tolist() |
594 allItems = var.tolist() |
588 |
595 |
650 _TypeMap.append((long, None)) # __IGNORE_WARNING__ |
657 _TypeMap.append((long, None)) # __IGNORE_WARNING__ |
651 except Exception: # secok |
658 except Exception: # secok |
652 pass # not available on all Python versions |
659 pass # not available on all Python versions |
653 |
660 |
654 try: |
661 try: |
655 _TypeMap.append((unicode, None)) # __IGNORE_WARNING__ |
|
656 except Exception: # secok |
|
657 pass # not available on all Python versions |
|
658 |
|
659 try: |
|
660 import array |
662 import array |
661 _TypeMap.append((array.array, arrayResolver)) |
663 _TypeMap.append((array.array, arrayResolver)) |
662 except ImportError: |
664 except ImportError: |
663 pass # array.array may not be available |
665 pass # array.array may not be available |
664 |
666 |