Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>No urgent need to create a function, if you don't require one:</p> <pre><code>&gt;&gt;&gt; tpl = "&lt;a href='mailto:%s'&gt;%s&lt;/a&gt;" &gt;&gt;&gt; s = tpl % ('matt.rez@where.com', 'matt rez', ) &gt;&gt;&gt; print s "&lt;a href='mailto:matt.rez@where.com'&gt;matt rez&lt;/a&gt;" </code></pre> <p>If you're on 2.6+ you can alternatively use the new <code>format</code> function along with its mini language:</p> <pre><code>&gt;&gt;&gt; tpl = "&lt;a href='mailto:{0}'&gt;{1}&lt;/a&gt;" &gt;&gt;&gt; s = tpl.format('matt.rez@where.com', 'matt rez') &gt;&gt;&gt; print s "&lt;a href='mailto:matt.rez@where.com'&gt;matt rez&lt;/a&gt;" </code></pre> <p>Wrapped in a function:</p> <pre><code>def render_user(userinfo, template="&lt;a href='mailto:{0}'&gt;{1}&lt;/a&gt;"): """ Renders a HTML link for a given ``userinfo`` tuple; tuple contains (email, name) """ return template.format(userinfo) # Usage: userinfo = ('matt.rez@where.com', 'matt rez') print render_user(userinfo) # same output as above </code></pre> <p>Extra credit:</p> <p>Instead of using a normal <code>tuple</code> object try use the more robust and human friendly <a href="http://docs.python.org/dev/library/collections.html#collections.namedtuple" rel="noreferrer"><code>namedtuple</code></a> provided by the <code>collections</code> module. It has the same performance characteristics (and memory consumption) as a regular <code>tuple</code>. An short intro into named tuples can be found in this PyCon 2011 Video (fast forward to ~12m): <a href="http://blip.tv/file/4883247" rel="noreferrer">http://blip.tv/file/4883247</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload