Superimpose.py

From XPUB & Lens-Based wiki
Revision as of 10:54, 23 November 2013 by Michael Murtaugh (talk | contribs)

Description

Superimposes ascii art

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