Popular recipes tagged "comparison"http://code.activestate.com/recipes/tags/comparison/popular/2016-03-28T21:36:31-07:00ActiveState Code RecipesFile comparison utility in Python (Python)
2016-03-26T18:31:11-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580631-file-comparison-utility-in-python/
<p style="color: grey">
Python
recipe 580631
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/comparison/">comparison</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>).
</p>
<p>This is a recipe to compare any two files via a Python command-line program.
It is like a basic version of the cmp command of Unix or the fc.exe (file compare) command of Windows.</p>
Python one-liner to compare two files (Python)
2016-03-28T21:36:31-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580632-python-one-liner-to-compare-two-files/
<p style="color: grey">
Python
recipe 580632
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/comparison/">comparison</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/programming/">programming</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>As the title says ...</p>
<p>It prints True if the files compared are the same, and False if they differ (either in size or in content).</p>
Range comparison (Python)
2012-06-06T12:00:52-07:00Charlie Clarkhttp://code.activestate.com/recipes/users/4171013/http://code.activestate.com/recipes/578158-range-comparison/
<p style="color: grey">
Python
recipe 578158
by <a href="/recipes/users/4171013/">Charlie Clark</a>
(<a href="/recipes/tags/case/">case</a>, <a href="/recipes/tags/comparison/">comparison</a>, <a href="/recipes/tags/switch/">switch</a>, <a href="/recipes/tags/ternary/">ternary</a>).
</p>
<p>Although Python now has something similar to ternary operator with the result if ... else other result construction and this allows chaining (adding additional conditions on the if side, this soon becomes unreadable. A common use case is to filter values by ranges so I wrote the following when porting some code from PHP once I found I no longer understand the logic for a simple three-way filter.</p>
A script evaluating PSNR metric of two YUV420 frames (Python)
2011-04-08T07:26:45-07:00Denis Gorodetskiyhttp://code.activestate.com/recipes/users/4177587/http://code.activestate.com/recipes/577645-a-script-evaluating-psnr-metric-of-two-yuv420-fram/
<p style="color: grey">
Python
recipe 577645
by <a href="/recipes/users/4177587/">Denis Gorodetskiy</a>
(<a href="/recipes/tags/comparison/">comparison</a>, <a href="/recipes/tags/difference/">difference</a>, <a href="/recipes/tags/frame/">frame</a>, <a href="/recipes/tags/metric/">metric</a>, <a href="/recipes/tags/psnr/">psnr</a>, <a href="/recipes/tags/video/">video</a>, <a href="/recipes/tags/yuv/">yuv</a>).
Revision 2.
</p>
<p>A script evaluating PSNR metric of two YUV420 frames
<strong>usage: psnr.py filename1.yuv filename2.yuv frame_width frame_height</strong></p>
<p>Alternatively if filename1 contains width and height in the form <strong>file-1200x1600.yuv</strong>,
the script will extract width and height of a frame from the filename. Then usage even simplier:
<strong>psnr.py filename1-1200x1600.yuv filename2.yuv</strong></p>
Compare MySQL DB (Python)
2016-02-11T17:31:39-08:00Jice Clavierhttp://code.activestate.com/recipes/users/4089467/http://code.activestate.com/recipes/576589-compare-mysql-db/
<p style="color: grey">
Python
recipe 576589
by <a href="/recipes/users/4089467/">Jice Clavier</a>
(<a href="/recipes/tags/compare/">compare</a>, <a href="/recipes/tags/comparison/">comparison</a>, <a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/mysql/">mysql</a>).
Revision 3.
</p>
<p>Small module to and check for differences between 2 DB.</p>
<p>It will compare the table list, the tables structure and their content.</p>
<p>When you run the program, you are ask if you want a detailed comparison.
As global comparison will list all the different tables, detailed comparison will output
every different record (and will take longer to run)</p>
Total Ordering: Class Decorator for Filling in Rich Comparison Methods When Only One is Implemented (Python)
2008-10-28T11:54:42-07:00Michael Foordhttp://code.activestate.com/recipes/users/2183852/http://code.activestate.com/recipes/576529-total-ordering-class-decorator-for-filling-in-rich/
<p style="color: grey">
Python
recipe 576529
by <a href="/recipes/users/2183852/">Michael Foord</a>
(<a href="/recipes/tags/class_decorator/">class_decorator</a>, <a href="/recipes/tags/comparison/">comparison</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/ordering/">ordering</a>, <a href="/recipes/tags/sorting/">sorting</a>).
Revision 5.
</p>
<p><code>total_ordering</code> and <code>force_total_ordering</code> are class decorators for
Python 2.6 & Python 3.</p>
<p>They provides <em>all</em> the rich comparison methods on a class by defining <em>any</em>
one of '__lt__', '__gt__', '__le__', '__ge__'.</p>
<p><code>total_ordering</code> fills in all unimplemented rich comparison methods, assuming
at least one is implemented. <code>__lt__</code> is taken as the base comparison method
on which the others are built, but if that is not available it will be
constructed from the first one found.</p>
<p><code>force_total_ordering</code> does the same, but having taken a comparison method as
the base it fills in <em>all</em> the others - this overwrites additional comparison
methods that may be implemented, guaranteeing consistent comparison semantics.</p>