Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a79ec22f
Commit
a79ec22f
authored
Sep 10, 2004
by
Andrew M. Kuchling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update PEP292 section
parent
dff68d0c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
10 deletions
+5
-10
Doc/whatsnew/whatsnew24.tex
Doc/whatsnew/whatsnew24.tex
+5
-10
No files found.
Doc/whatsnew/whatsnew24.tex
View file @
a79ec22f
...
...
@@ -213,27 +213,22 @@ Unicode string:
\begin{verbatim}
>>> import string
>>> t = string.Template('
$
page:
$
title')
>>> t
% {'page':2, 'title': 'The Best of Times'}
>>> t
.substitute(
{
'page':2, 'title': 'The Best of Times'
}
)
u'2: The Best of Times'
>>> t2
% {'cost':42.50, 'action':'polish'}
u'
$
42
.
5
: polishing'
\end{verbatim}
% $ Terminate $-mode for Emacs
If a key is missing from the dictionary, the
\
class
{
Template
}
class
will raise a
\exception
{
KeyError
}
. There's also a
\
class
{
SafeTempla
te
}
class
that ignores missing keys:
If a key is missing from the dictionary, the
\
method
{
substitute
}
method
will raise a
\exception
{
KeyError
}
. There's also a
\
method
{
safe
_
substitu
te
}
method
that ignores missing keys:
\begin{verbatim}
>>> t = string.SafeTemplate('
$
page:
$
title')
>>> t
% {'page':3}
>>> t
.safe
_
substitute(
{
'page':3
}
)
u'3:
$
title'
\end
{
verbatim
}
Because templates are Unicode strings, you can use a template with the
\module
{
gettext
}
module to look up translated versions of a message.
\begin
{
seealso
}
\seepep
{
292
}{
Simpler String Substitutions
}{
Written and implemented
by Barry Warsaw.
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment