mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
tutorial: added example for callable environment variable (#5585)
* doc * doc --------- Co-authored-by: a <1@1.1>
This commit is contained in:
parent
77f42b2f85
commit
96c2c0af14
2 changed files with 46 additions and 0 deletions
|
@ -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
23
news/call_env.rst
Normal 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>
|
Loading…
Add table
Reference in a new issue