Monday, July 25, 2011

Python Superscript

similar to my last post about bash scripting with "basename" functionality, here is an example python module to determine the name of the link being called as well as the arguments supplied:


#!/usr/bin/env python
#-*- coding:utf-8 -*-

"""
        PROJECT - MODULE:
                Python-SuperScript.py

        DESCRIPTION:
                example basename functionality handling in python

        @copyright: 2011 by nairb <code@nairb.us>
        @license: GNU GPL, see COPYING for details.
"""

import os, sys, string

class App(object):
        """ Class doc """
     
        def __init__ (self):
                """ Class initialiser """
                pass
             
        def progName(self):
                """  Return the program name of running script
                @param: none
                @return: base name of the running script
                """
                argvz=string.split(sys.argv[0], '/')
                return argvz[len(argvz)-1]
             
        def progArgs(self):
                """ Return the array of arguments given
                @param: none
                @return: the arguments passed to script
                """
                return sys.argv[1:]

        def Main(self):
                """ Main Function
                @param PARAM:
                @return RETURN:
                """
                print "This program was called as:\n\t" + str(self.progName()) + "\n\nArguments where passed of:\n\t" + str(self.progArgs())
     
if __name__ == '__main__':
    a=App()
    a.Main()

hope someone finds this useful

No comments:

Post a Comment