|
Re: Question regarding passing external commandline arguements: msg#00005lang.jython.user
<Srikrishna_Parthasarathy <at> timeinc.com> writes: > > I am new to Jython . I have the following .py file . This > has been created based on BEA’s doc. I used to create a weblogic domain. > I want the py script to be more generic. I run now using > > > > Java weblogic.WLST filename.py Why not pass in your arguments as command line flags and command line arguments? You can use the getopt module, which is available to Jython, to parse flags and arguments. Would that solve your problem? If so, below is a sample script taken from some boiler plate that I use. You can run this script with something like the following: $ jython test_clargs.py --myflag=somevalue myargument or: $ jython test_clargs.py -m somevalue myargument Dave ============================================================= # test_clargs.py import sys import getopt def test(flag, arg1): print 'flag: "%s"' % (flag, ) print 'arg: "%s"' % (arg1, ) USAGE_TEXT = """ Usage: python test_clargs.py [options] Options: -h, --help Display this help message. Example: python test_clargs.py --myflag=somevalue arg1 """ def usage(): print USAGE_TEXT sys.exit(-1) def main(): args = sys.argv[1:] try: opts, args = getopt.getopt(args, 'hm:', ['help', 'myflag=']) except: usage() myflag = None for opt, val in opts: if opt in ('-h', '--help'): usage() elif opt in ('-m', '--myflag'): myflag = val if len(args) != 1: usage() test(myflag, args[0]) if __name__ == '__main__': main() ============================================================= ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Question regarding passing external commandline arguements, Srikrishna_Parthasarathy |
|---|---|
| Next by Date: | Special method names problem?, Eugene Rosenzweig |
| Previous by Thread: | Question regarding passing external commandline arguements, Srikrishna_Parthasarathy |
| Next by Thread: | RE: Re: Question regarding passing external commandline arguements, Srikrishna_Parthasarathy |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |