Next / Previous / Contents / TCC Help System / NM Tech homepage

3.3. main()

There are only two possible error conditions: wrong number of command line arguments; the argument is not a float.

conjd
# - - -   m a i n

def main():
    """conjd main program.
    """

    #-- 1 --
    # [ if  sys.argv[1:] is a single float ->
    #     j  :=  that float
    #   else ->
    #     sys.stderr  +:=  error message
    #     stop execution ]
    argList  =  sys.argv[1:]
    if  len(argList) != 1:
        usage ( "Wrong argument count." )
    else:
        try:
            j  =  float ( argList[0] )
        except ValueError, detail:
            usage ( "Invalid argument: %s" % detail )

First we make j into a JulianDate instance. Then we use the .datetime() method on that instance to get a regular datetime.datetime instance. Final output is produced by applying str() to the datetime, which produces an ISO date.

conjd
    #-- 2 --
    # [ jd  :=  a JulianDate instance for Julian date j ]
    jd  =  JulianDate ( j )

    #-- 3 --
    # [ dt  :=  jd as a datetime.datetime instance ]
    dt  =  jd.datetime()

    #-- 4 --
    # [ sys.stdout  +:=  dt in ISO form ]
    print str(dt)