Return a dataset class instance based on a string, tuple or dictionary .. code-block:: python iris = json_call('datasets.toy.Iris') This function works by parsing the string, and calling import and getattr a lot. (XXX)
(json, args=(), kwargs=None)
| 77 | |
| 78 | |
| 79 | def json_call(json, args=(), kwargs=None): |
| 80 | """ |
| 81 | Return a dataset class instance based on a string, tuple or dictionary |
| 82 | |
| 83 | .. code-block:: python |
| 84 | |
| 85 | iris = json_call('datasets.toy.Iris') |
| 86 | |
| 87 | This function works by parsing the string, and calling import and getattr a |
| 88 | lot. (XXX) |
| 89 | |
| 90 | """ |
| 91 | if kwargs is None: |
| 92 | kwargs = {} |
| 93 | if isinstance(json, basestring): |
| 94 | symbol = json_lookup(json) |
| 95 | return symbol(*args, **kwargs) |
| 96 | elif isinstance(json, dict): |
| 97 | raise NotImplementedError("dict calling convention undefined", json) |
| 98 | elif isinstance(json, (tuple, list)): |
| 99 | raise NotImplementedError("seq calling convention undefined", json) |
| 100 | else: |
| 101 | raise TypeError(json) |
| 102 | |
| 103 | |
| 104 | def get_obj(f, argfile=None, argstr=None, args=(), kwargs=None): |
no test coverage detected