(patch for Bash) adding Python features to Bash

Skip Montanaro skip at pobox.com
Thu Feb 13 07:28:08 EST 2003


    William> To Python and Bash users:

    William> I got tired of going back and forth between Python and Bash.
    William> So, I added few Python features to the shell....

    William> 1.  Integer sequence generator:
    ...

I've had this in my personal bin directory for about three years:

    #!/usr/bin/env python

    import sys, string

    def usage():

        print """
    usage:
            range high
            range high step
            range low high step

      In first case, low == 0 is implied
      If no step size is given, 1 is assumed
    """
        sys.exit(1)

    low = 0
    step = 1
    try:
        if len(sys.argv) == 2:
            high = int(sys.argv[1])
        elif len(sys.argv) == 3:
            high = int(sys.argv[1])
            step = int(sys.argv[2])
        elif len(sys.argv) == 4:
            low = int(sys.argv[1])
            high = int(sys.argv[2])
            step = int(sys.argv[3])
        else:
            raise RuntimeError
    except:
        usage()

    print string.join(map(str, range(low, high, step)))

Works well enough for my needs.  I never missed map or filter, though maybe
a patch for list comprehensions would be a good idea. <wink>

Skip





More information about the Python-list mailing list