add download link on full code listings

This commit is contained in:
Mark Pilgrim
2009-02-06 23:45:03 -05:00
parent 8b300049d9
commit dd7fdb87ac
5 changed files with 40 additions and 5 deletions
+1 -1
View File
@@ -3,6 +3,6 @@ FileETag MTime Size
Options -Indexes
DirectoryIndex index.html
AddType text/plain .txt
AddType text/plain .py
AddType application/x-python .py
AddType image/x-icon .ico
AddDefaultCharset utf-8
+1 -1
View File
@@ -15,7 +15,7 @@ pre{white-space:pre-wrap;padding-left:2.154em;line-height:1.75;border-left:1px d
pre,kbd,code,samp{font-family:Consolas,Inconsolata,Monaco,monospace;font-size:medium;word-spacing:0}
pre a{padding:0.4375em 0;border:0}
pre a:hover{border:0}
.widgets,.widgets a{font-size:small}
.widgets,.widgets a,.download{font-size:small}
.widgets a{color:#1b67c9;text-decoration:underline;padding:0}
kbd{font-weight:bold}
.prompt{color:#667}/*the neighbor of the beast*/
+10 -1
View File
@@ -60,7 +60,16 @@ for (var i = arPre.length - 1; i >= 0; i--) {
id = "autopre" + i;
elmPre.id = id;
}
elmPre.innerHTML = '<div id="' + id + 'widgets" class="widgets">[<a id="' + id + 'toggle" class="toggle" href="javascript:toggleBlock(\'' + id + '\')">hide</a>] [<a id="' + id + 'plaintext" href="javascript:plainTextOnClick(\'' + id + '\')">open in new window</a>]</div><div id="' + id + 'block">' + elmPre.innerHTML + '</div>';
var usDownload = '';
var elmDownload = elmPre.previousSibling;
while (elmDownload && (elmDownload.nodeType != 1)) {
elmDownload = elmDownload.previousSibling;
}
if (elmDownload && (elmDownload.nodeName.toLowerCase() == 'p') && (elmDownload.className == 'download')) {
usDownload = ' ' + elmDownload.innerHTML;
elmDownload.parentNode.removeChild(elmDownload);
}
elmPre.innerHTML = '<div id="' + id + 'widgets" class="widgets">[<a id="' + id + 'toggle" class="toggle" href="javascript:toggleBlock(\'' + id + '\')">hide</a>] [<a id="' + id + 'plaintext" href="javascript:plainTextOnClick(\'' + id + '\')">open in new window</a>]' + usDownload + '</div><div id="' + id + 'block">' + elmPre.innerHTML + '</div>';
}
}
+23
View File
@@ -40,3 +40,26 @@ def approximate_size(size, a_kilobyte_is_1024_bytes=True):
if __name__ == "__main__":
print(approximate_size(1000000000000, False))
print(approximate_size(1000000000000))
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
+5 -2
View File
@@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>Your first Python program - Dive into Python 3</title>
<link rel="stylesheet" type="text/css" href="dip3.css">
<script type="text/javascript" src="dip3.packed.js"></script>
<script type="text/javascript" src="dip3.js"></script>
<link rel="shortcut icon" href="data:image/ico,">
<link rel="alternate" type="application/atom+xml" href="http://hg.diveintopython3.org/atom-log">
<style type="text/css">
@@ -38,7 +38,9 @@ body{counter-reset:h1 1}
</ol>
<h2 id="divingin">Diving in</h2>
<p class="fancy">You know how other books go on and on about programming fundamentals and finally work up to building something useful? Let's skip all that. Here is a complete, working Python program. It probably makes absolutely no sense to you. Don't worry about that, because you're going to dissect it line by line. But read through it first and see what, if anything, you can make of it.
<pre><code class="python">SUFFIXES = {1000: ('KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'),
<!-- FIXME: download link -->
<p class="download">[<a href="humansize.py">download</a>]</p>
<pre><code>SUFFIXES = {1000: ('KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'),
1024: ('KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB')}
def approximate_size(size, a_kilobyte_is_1024_bytes=True):
@@ -74,6 +76,7 @@ if __name__ == "__main__":
<pre class="screen"><samp class="prompt">you@localhost:~$ </samp><kbd>python3 humansize.py</kbd>
<samp>1.0 TB
931.3 GiB</samp></pre>
<!-- FIXME: this would be a good place to explain what the program, you know, actually does -->
<h2 id="declaringfunctions">Declaring functions</h2>
<p>Python has functions like most other languages, but it does not have separate header files like <abbr>C++</abbr> or <code>interface</code>/<code>implementation</code> sections like Pascal. When you need a function, just declare it, like this:
<pre><code>def approximate_size(size, a_kilobyte_is_1024_bytes=True):</code></pre>