Superimpose.py: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "== Code == <source lang="python"> import itertools import sys for x, y in zip(open(sys.argv[1]), open(sys.argv[2])): for xc, yc in itertools.izip_longest(x.rstrip('\r\n')...")
 
No edit summary
Line 1: Line 1:
== Usage ==
figlet hello > hello.txt
figlet world > world.txt
python superimpose hello.txt world.txt
produces...
<pre>
_          _ _    _    _
__|__  _____| _ __| | __| |
\ \_/\ / / _ \||'__|\|/ _` |
|\|V| V /_(_)||||(_| | (_| |
|_\_/\_/_\___/|_|__|_|\__,_|
</pre>
== Code ==
== Code ==
<source lang="python">
<source lang="python">

Revision as of 11:53, 23 November 2013

Usage

figlet hello > hello.txt
figlet world > world.txt
python superimpose hello.txt world.txt

produces...

 _          _ _     _     _ 
__|__   _____| _ __| | __| |
\ \_/\ / / _ \||'__|\|/ _` |
|\|V| V /_(_)||||(_| | (_| |
|_\_/\_/_\___/|_|__|_|\__,_|

Code

import itertools
import sys

for x, y in zip(open(sys.argv[1]), open(sys.argv[2])):
    for xc, yc in itertools.izip_longest(x.rstrip('\r\n'), y.rstrip('\r\n'), fillvalue=' '):
        if yc == ' ':
            sys.stdout.write(xc);
        else:
            sys.stdout.write(yc);
    sys.stdout.write('\n')

Source: Alexandre Leray