You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can also hand the handling of names over to a function, if you prefer:
276
276
277
277
278
-
.. code-block:: python
278
+
.. code-block:: pycon
279
279
280
280
>>> def name_handler(node):
281
281
return ord(node.id[0].lower(a))-96
@@ -284,9 +284,34 @@ You can also hand the handling of names over to a function, if you prefer:
284
284
3
285
285
286
286
That was a bit of a silly example, but you could use this for pulling values
287
-
from a database or file, say, or doing some kind of caching system.
287
+
from a database or file, looking up spreadsheet cells, say, or doing some kind of caching system.
288
+
289
+
In general, when it attempts to find a variable by name, if it cannot find one,
290
+
then it will look in the ``functions`` for a function of that name. If you want your name handler
291
+
function to return an "I can't find that name!", then it should raise a ``simpleeval.NameNotDefined``
292
+
exception. Eg:
288
293
289
-
The two default names that are provided are ``True`` and ``False``. So if you want to provide your own names, but want ``True`` and ``False`` to keep working, either provide them yourself, or ``.copy()`` and ``.update`` the ``DEFAULT_NAMES``. (See functions example above).
0 commit comments