Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>ok, for web applications, support for python is going to be based on whether or not the browser has python support either provided as a plugin or built in to the browser. it probably isn't a good idea to rely on this being the case for most people who view the application. If you do, its just a matter of including the script in a <code>&lt;SCRIPT type="text/x-python" src="path-to-your-pyfile.py"&gt;</code> tag in the html. As an alternative, javascript, thanks to html5 now has support to write to files with both text and binary data. See the file api <a href="http://www.w3.org/TR/file-writer-api/" rel="nofollow">here</a>.</p> <p>if there there is a problem with using the file api, you can always create a link to a file for the user to save from javascript using data URIs like so:</p> <p>data:text/plain;base64,aGVsbG8gZnJvbSBhIGRhdGEgdXJpISEh</p> <p>here is an example of an html file that generates files on the fly from javascript note i rolled my own base64 encoder but there are many js libraries available for this.</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;title&gt;&lt;/title&gt; &lt;SCRIPT type="text/javascript" &gt; var BASE_64_ALPHABET =//for encoding base64 [ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z', 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', '0','1','2','3','4','5','6','7','8','9','+','/' ]; var BASE_64_PAD = '='; function valueAt(source,index) { var result = null; if(source.charAt) result = source.charAt(index); else result = source[index]; if(result.charCodeAt) result = result.charCodeAt(0); if(result === null | result === undefined) return 0; return result; } function toBase64(data, offset, length) { var padSize = (3-(length % 3)); if(padSize == 3 &amp;&amp; length != 0) padSize = 0; var bufferSize = ((4*(length-(length%3)))/3); + padSize; var buffer = new Array(bufferSize); var iterationLimit = length + (length % 3) - 1; var octetMask = 0xFF; var sextetMask = 0x3F; for(var sourceIndex=0,destinationIndex=0;sourceIndex&lt;iterationLimit;sourceIndex+=3,destinationIndex+=4) { var readBlock = ( ((valueAt(data, offset+sourceIndex) &amp; octetMask) &lt;&lt; 16) | ((valueAt(data, offset+sourceIndex+1) &amp; octetMask) &lt;&lt; 8) | (valueAt(data, offset+sourceIndex+2) &amp; octetMask) ); buffer[destinationIndex] = BASE_64_ALPHABET[(readBlock &gt;&gt;&gt; 18) &amp; sextetMask]; buffer[destinationIndex+1] = BASE_64_ALPHABET[(readBlock &gt;&gt;&gt; 12) &amp; sextetMask]; buffer[destinationIndex+2] = BASE_64_ALPHABET[(readBlock &gt;&gt;&gt; 6) &amp; sextetMask]; buffer[destinationIndex+3] = BASE_64_ALPHABET[readBlock &amp; sextetMask]; } for(var i = 0; i &lt; padSize; i++) buffer[buffer.length - 1 - i] = BASE_64_PAD; return buffer.join(""); } function makeDataURI() { var data = document.getElementById("datasource").value; var mime = document.getElementById("mimesource").value; alert("data:"+mime+";base64,"+toBase64(data,0,data.length)); } &lt;/SCRIPT&gt; &lt;/head&gt; &lt;body&gt; &lt;INPUT id="datasource" type="text" value="enter your file data here"&gt;&lt;/INPUT&gt; &lt;INPUT id="mimesource" type="text" value="enter your mime type here"&gt;&lt;/INPUT&gt; &lt;INPUT type="button" onclick="makeDataURI();" value="Generate URI"&gt;&lt;/INPUT&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

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