Python Forum
between.py - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Code sharing (https://python-forum.io/forum-5.html)
+--- Thread: between.py (/thread-15691.html)



between.py - Skaperen - Jan-29-2019

i even had some uses for this script today. it merges each line of input between each argument from the command then outputs as many lines as it inputs. typical uses involve file names or other lists. normally 2 arguments are required. but you can make them be empty strings.

between.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import print_function
from sys import argv,stdin,stderr
argcount=len(argv)
if argcount<3:
    print('need 2 or more arguments',file=stderr)
    exit(1)
for input in stdin:
    if not input:
        continue
    while input and ord(input[-1])<32:
        input=input[:-1]
    output=argv[1]
    for argx in range(2,argcount):
        output=output+input+argv[argx]
    print(output)