CLI Pipeline I/O


CLI Pipeline I/O

1. Question

Using CLI pipeline, “|”, pass the previous output to the next function/script as input

2. User Case

using the example.json contents as the input for parse_data.py

cat example.json | python3 parse_data.py

3. Solutions

using the fileinput module

#!/usr/bin/env python3
import fileinput

with fileinput.input() as f_input:
    for line in f_input:
        print(line, end='')

Reference


Author: NI
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source NI !
  TOC