Popular recipes by Tony Flury http://code.activestate.com/recipes/users/4184150/2012-12-15T19:24:18-08:00ActiveState Code RecipesHuman readable file/memory sizes (Python)
2012-11-05T11:59:20-08:00Tony Fluryhttp://code.activestate.com/recipes/users/4184150/http://code.activestate.com/recipes/578321-human-readable-filememory-sizes/
<p style="color: grey">
Python
recipe 578321
by <a href="/recipes/users/4184150/">Tony Flury</a>
(<a href="/recipes/tags/formatting/">formatting</a>, <a href="/recipes/tags/memory/">memory</a>, <a href="/recipes/tags/size/">size</a>).
Revision 5.
</p>
<p>In writing a application to display the file sizes of set of files, I wanted to provide a human readable size rather then just displaying a byte count (which can get rather big).</p>
<p>I developed this useful short recipe that extends the format specifier mini Language to add the S presentation type - which will intelligently convert the value to be displayed into a known human readable size format - i.e. b, Kb,Mb, Gb etc. It honours the rest of the format specification language (<a href="http://docs.python.org/2/library/string.html#format-string-syntax%29" rel="nofollow">http://docs.python.org/2/library/string.html#format-string-syntax)</a></p>
<p>It uses a factor of 1024 at each stage</p>
Simple Finite State Machine class - v2 (Python)
2012-12-15T19:24:18-08:00Tony Fluryhttp://code.activestate.com/recipes/users/4184150/http://code.activestate.com/recipes/578344-simple-finite-state-machine-class-v2/
<p style="color: grey">
Python
recipe 578344
by <a href="/recipes/users/4184150/">Tony Flury</a>
(<a href="/recipes/tags/automation/">automation</a>, <a href="/recipes/tags/finitestatemachine/">finitestatemachine</a>, <a href="/recipes/tags/tokeniser/">tokeniser</a>).
Revision 4.
</p>
<p>This may not be useful to many people, but this is a very simple finite state machine. It is defined as a class so that you can have multiple state machines running at the same time - all with different state/transition lists.</p>
Human readable file/memory sizes v2 (Python)
2012-11-11T17:28:57-08:00Tony Fluryhttp://code.activestate.com/recipes/users/4184150/http://code.activestate.com/recipes/578323-human-readable-filememory-sizes-v2/
<p style="color: grey">
Python
recipe 578323
by <a href="/recipes/users/4184150/">Tony Flury</a>
(<a href="/recipes/tags/formatting/">formatting</a>, <a href="/recipes/tags/memory/">memory</a>, <a href="/recipes/tags/size/">size</a>).
</p>
<p>In writing a application to display the file sizes of set of files, I wanted to provide a human readable size rather then just displaying a byte count (which can get rather big).</p>
<p>I developed this useful short recipe that extends the format specifier mini Language to add new presentation type s- which will intelligently convert the value to be displayed into a known human readable size format - i.e. b, Kb,Mb, Gb, B, KB etc. It honours the rest of the format specification language (<a href="http://docs.python.org/2/library/string.html#format-string-syntax%29" rel="nofollow">http://docs.python.org/2/library/string.html#format-string-syntax)</a></p>
<p>It uses a factor of 1024 for IEC and common formats, and factor of 1000 for SI units.</p>
Simple Finite State Machine class (Python)
2012-11-20T14:37:34-08:00Tony Fluryhttp://code.activestate.com/recipes/users/4184150/http://code.activestate.com/recipes/578332-simple-finite-state-machine-class/
<p style="color: grey">
Python
recipe 578332
by <a href="/recipes/users/4184150/">Tony Flury</a>
(<a href="/recipes/tags/automation/">automation</a>, <a href="/recipes/tags/finitestatemachine/">finitestatemachine</a>, <a href="/recipes/tags/tokeniser/">tokeniser</a>).
</p>
<p>This may not be useful to many people, but this is a very simple finite state machine. It is defined as a class so that you can have multiple state machines running at the same time - all with different state/transition lists.</p>