Python Option HandlingΒΆ

Since Python 2.7 argparse is the recommended Python module for handling command line arguments. It provides a very advanced and flexible object-oriented API for handling command lines. An example of how to use argparse can be found in executable.py in the example project:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
def sendMagicNumber():
    
    from rsb import createInformer, Scope
    import argparse
    
    parser = argparse.ArgumentParser(description='An example program sending some magic numbers')
    parser.add_argument('--magicnumber', type=int, required=True,
                        help='magic number to transform and send')
    parser.add_argument('--scope', type=str, default='/an/example',
                        help='scope to send on')
    args = parser.parse_args()

    # create an informer for integers
    informer = createInformer(args.scope, dataType=int)

    # send some events using a method that directly accepts data
    informer.publishData(MagicNumberTransformer().transform(args.magicnumber))

    informer.deactivate()