Skip to content
This repository was archived by the owner on Apr 24, 2018. It is now read-only.
This repository was archived by the owner on Apr 24, 2018. It is now read-only.

Idea: Use __or__ for chaining #2

Open
@rconradharris

Description

@rconradharris

For the common case linking stdout to stdin of another process, we could use the 'pipe' syntax from shells by overloading the __or__ method.

Part of me thinks this is way too clever (in a bad way)... the other half thinks this would be really awesome/elegant.

Just an example:

class PipeCommand(object):
    def __init__(self, cmd):
        self.cmd = cmd
    def __repr__(self):
        return self.cmd
    def __or__(self, other):
        return PipeCommand('|'.join([self.cmd, other.cmd]))                                                                                                                                                        

def run(cmd):
    return PipeCommand(cmd)

print run('cat') | run('wc -l')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions