tutorial: added example for callable environment variable (#5585)

* doc

* doc

---------

Co-authored-by: a <1@1.1>
This commit is contained in:
Andy Kipp 2024-07-14 21:04:24 +02:00 committed by GitHub
parent 77f42b2f85
commit 96c2c0af14
Failed to generate hash of commit
2 changed files with 46 additions and 0 deletions

View file

@ -246,6 +246,29 @@ They can be seen on the `Environment Variables page <envvars.html>`_.
``KeyError`` will be raised if the variable does not exist in the ``KeyError`` will be raised if the variable does not exist in the
environment. environment.
Callable Environment Variables
------------------------------
In some cases you may want to have environment variable with dynamically created value.
Here is the example of callable environment variable:
.. code-block:: xonshcon
>>> class Stamp:
... """Return current date as string representation."""
... def __repr__(self):
... from datetime import datetime
... return str(datetime.now().isoformat())
...
...
>>> $DT = Stamp()
>>> $DT
2024-11-11T11:11:22
>>> echo $DT
2024-11-11T11:11:33
>>> env | grep DT
DT=2024-11-11T11:11:44
Running Commands Running Commands
============================== ==============================

23
news/call_env.rst Normal file
View file

@ -0,0 +1,23 @@
**Added:**
* Tutorial: added example of callable environment variable.
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* <news item>
**Security:**
* <news item>