string.Template

    

index 6148afa..1cc281b 100644
@@ -23,7 +23,6 @@ These are ideas for future posts. Let me know if you want to write a guest post
+ Subprocess and env vars
+ Subprocess pipe
+ Unicode module
-+ String.Template
+ String module consts
+ Urllib
+
diff --git a/pythonetc/string-template.md b/pythonetc/string-template.md
new file mode 100644
index 0000000..e5715c9
--- /dev/null
+++ b/pythonetc/string-template.md
@@ -0,0 +1,23 @@
+# string.Template
+
+Published: 2022-09-20.
+
+The [string.Template](https://docs.python.org/3/library/string.html#template-strings) class allows to do $-style substitutions: + +python +from string import Template +t = Template('Hello,$channel!')
+
+t.substitute(dict(channel='@pythonetc'))
+# 'Hello, @pythonetc!'
+
+t.safe_substitute(dict())
+# 'Hello, \$channel!'
+
+
+Initially, it [was introduced](https://peps.python.org/pep-0292/) to simplify translations of strings. However, now [PO-files](https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html) natively support [python-format](https://www.gnu.org/software/gettext/manual/html_node/python_002dformat.html) flag. It indicates for translators that the string has str.format-style substitutions. And on top of that, str.format is much more powerful and flexible.
+
+Nowadays, the main purpose of Template is to confuse newbies with [one more way to format a string](https://t.me/pythonetc/610). Jokes aside, there are a few more cases when it can come in handy:
+
++ Template.safe_substitute can be used when the template might have variables that aren't defined and should be ignored.
++ The substitution format is similar to the string substitution in bash (and other shells), which is useful in some cases. For instance, if you want to write your own [dotenv](https://github.com/motdotla/dotenv).
diff --git a/pythonetc/warnings.md b/pythonetc/warnings.md
index ae0e6bb..7082980 100644
--- a/pythonetc/warnings.md
+++ b/pythonetc/warnings.md
@@ -1,5 +1,7 @@
# warnings

+Published: 2022-09-13.
+
The module [warnings](https://docs.python.org/3/library/warnings.html) allows to print, you've guessed it, warnings. Most often, it is used to warn users of a library that the module, function, or argument they use is deprecated.

python

`