Top-rated recipes tagged "representation" Code RecipesConvert Byte Size to String Representation (Python) 2012-04-13T19:55:07-07:00Stephen Chappell <p style="color: grey"> Python recipe 576924 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/representation/">representation</a>). Revision 4. </p> <p>In anticipation of creating large data structure, it appeared to be helpful if the users could get an idea of how much memory (RAM in particular) would be used while attempting to create a large, multidimensional array. In order to convert the calculated size into a precise, human-readable format, the follow code was devised. In order to convert a number into an equivalent representation of bytes, just call the "convert" function while providing the number as its argument. The other functions are currently public in case anyone else finds them useful.</p> Number of bits needed to store an integer, and its binary representation (Python) 2017-03-12T23:10:48-07:00Vasudev Ram <p style="color: grey"> Python recipe 580762 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/formats/">formats</a>, <a href="/recipes/tags/integers/">integers</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/representation/">representation</a>, <a href="/recipes/tags/type/">type</a>). </p> <p>This recipe shows how to find, via Python code, the number of bits needed to store an integer, and how to generate its binary representation. It does this for integers from 0 to 256.</p> <p>More details and full output here:</p> <p><a href="" rel="nofollow"></a></p>, like the Unix od (octal dump) command (Python) 2015-11-01T12:43:38-08:00Vasudev Ram <p style="color: grey"> Python recipe 579120 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/dump/">dump</a>, <a href="/recipes/tags/hexadecimal/">hexadecimal</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/octal/">octal</a>, <a href="/recipes/tags/od/">od</a>, <a href="/recipes/tags/representation/">representation</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utility/">utility</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>This recipe implements a simple data dump tool, roughly like the od command of Unix, which stands for octal dump (though od can also dump data in hex and other formats). This tool dumps data in character and hex formats, in this version. This is version 1.</p> Converting numeric strings to integers (Python) 2015-08-04T20:08:29-07:00Vasudev Ram <p style="color: grey"> Python recipe 579093 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/formats/">formats</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/numerical/">numerical</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/representation/">representation</a>). </p> <p>This recipe shows how to convert numeric strings into integers, i.e. it emulates the Python int() function - partially. It does not handle negative numbers, floating point numbers, or numbers in other bases than decimal. It is only meant as a simple demo of the steps by which a string containing an integer value, is converted into an actual integer, in Python (and similarly, in other languages).</p> Convert datetime in python to user friendly representation. (Python) 2009-08-15T01:00:03-07:00Jai Vikram Singh Verma <p style="color: grey"> Python recipe 576880 by <a href="/recipes/users/4171450/">Jai Vikram Singh Verma</a> (<a href="/recipes/tags/ago/">ago</a>, <a href="/recipes/tags/datetime/">datetime</a>, <a href="/recipes/tags/parse/">parse</a>, <a href="/recipes/tags/representation/">representation</a>, <a href="/recipes/tags/string/">string</a>, <a href="/recipes/tags/user_friendly/">user_friendly</a>). </p> <p>A small contribution to the developer community.</p> <p>This module caters to the need of developers who want to put date &amp; time of post in terms like <br /> "X days, Y hrs ago", "A hours B mins ago", etc. in their applications rather then a basic timestamp <br /> like "2009-08-15 03:03:00". Additionally it also <br /> provides since epoch for a given datetime. </p> <p>It takes in a Python datetime object as an input <br /> and provides a fancy datetime (as I call it) and <br /> the seconds since epoch. </p>