From 96c2c0af14db07aead2a456bd8cc97770837bfd8 Mon Sep 17 00:00:00 2001 From: Andy Kipp Date: Sun, 14 Jul 2024 21:04:24 +0200 Subject: [PATCH] tutorial: added example for callable environment variable (#5585) * doc * doc --------- Co-authored-by: a <1@1.1> --- docs/tutorial.rst | 23 +++++++++++++++++++++++ news/call_env.rst | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 news/call_env.rst diff --git a/docs/tutorial.rst b/docs/tutorial.rst index f4eef2758..fcad90235 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -246,6 +246,29 @@ They can be seen on the `Environment Variables page `_. ``KeyError`` will be raised if the variable does not exist in the 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 ============================== diff --git a/news/call_env.rst b/news/call_env.rst new file mode 100644 index 000000000..4fc947118 --- /dev/null +++ b/news/call_env.rst @@ -0,0 +1,23 @@ +**Added:** + +* Tutorial: added example of callable environment variable. + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +*