(Sep-28-2017, 05:39 PM)nilamo Wrote: If you want to do it, then it doesn't matter whether or not I do it, right? Because you'd still end up doing it yourself anyway :pperhaps.
(Sep-28-2017, 06:02 PM)nilamo Wrote:off by one: i'm getting 1 more line than specified for the headimport sys def get_buffer_size(): buffer_size = 1 if len(sys.argv) > 1: buffer_size = abs(int(sys.argv[1])) return buffer_size def consume_input(buffer_size): buffer = head_sent = False for line in sys.stdin: buffer.append(line) if len(buffer) > buffer_size: if not head_sent: head_sent = True for line in buffer: print(line, end="") buffer = else: buffer.pop(0) if head_sent and buffer: print("-" * 78) for line in buffer: print(line, end="") if __name__ == "__main__": try: buffer_size = get_buffer_size() consume_input(buffer_size) except ValueError as err: print("Invalid buffer size. Any argument to this script should be a number.")
Output:E:\Projects\etc>pip help | headtail.py Usage: ------------------------------------------------------------------------------ download. Implied with --no-index. E:\Projects\etc>pip help | headtail.py -4 Usage: pip <command> [options] Commands: ------------------------------------------------------------------------------ --disable-pip-version-check Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
it looks like quoting source code loses indents.
perhaps i would code it anyway. coding is fun. but for headtail, i just want to have the tool.
i guess i will code one of my own to have something in a free license i can give away in a "collection of POSIX commands done in Python" unless nilamo puts his own in such a license (BSD, MIT, GPL, etc.).
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.