Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
between.py
#1
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)
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020