From: Updike, C. <Cla...@jh...> - 2003-07-18 15:54:59
|
You've got some particular users! I don't know of anything easy. Special methods won't help you there--it would require a new keyword, AFAIK. And it doesn't look like python plans on offering a 'help' keyword but rather a function based approach. The PEP on this issue is at: http://python.org/peps/pep-0233.html (note its status is deferred) BTW, the help function I provided doesn't do an: if (name=="connect"): print 'blah ' Rather, it prints the doc string of the referenced object, and you don't have to use quotes around the object name, you can use the object itself: >>> help(help) or >>> help('help') Maybe the absence of quotes would be sufficient to placate your users. -Clark -----Original Message----- From: Satya Ghattu [mailto:sg...@be...] Sent: Friday, July 18, 2003 10:46 AM To: Updike, Clark Cc: 'jyt...@li...' Subject: Re: [Jython-Users] Defining commands in the shell .... Yes, I defined a sitecustomize.py file under the Lib directory to run and set my environment, something like this: sitecustomize.py import sys def help(name): if (name == "connect"): print 'This command lets you connect to the server" The sitecustomize.py will be executed when you bring up an interactive session. I can do something like, >>> help("connect") And this will do what i want. But my question is can I do something like, >>> help connect with out the enclosing brackets? Calling help("connect") somehow doesn't seem natural. My users are complaining about that they do not want to call as if they are calling functions, they just want to be able to issue commands as if they are interacting with a command shell. Can this be achieved? Thanks for any help, -satya Updike, Clark wrote: You can run a script in the environment that sets up the help function before the interactive session takes over. I use this to set up lots of other stuff (database connections, app functions, variables) for users. I don't think the environment variable PYTHONSTARTUP (which runs the specified script in Python) does anything in Jython. However, this is how I achieve the same end. FILE PyEnv.py ---------------------------------------- # Sets up the custom command line environment. # Can also run user scripts before going interactive. # # FYI: calling batch file must use -i switch to go to an # interactive session after running the user's script. import sys # set up help function # users can run help on the function object: help(envFunc) # or on the string name of the function: help('envFunc') def help(subject='help'): """help([,subject]) -> None Put your high level help documentation goes here: List of environments variables, functions, etc. """ if hasattr(subject,'__doc__'): print subject.__doc__ # passed in function ref else: try: exec("print " + subject + ".__doc__") except NameError, e: print "Nothing found by the name '" + subject + "'" # set up anything else you want (variables, other fuctions, etc.) # run user's script if present (argv[1]) if len(sys.argv) > 1: execfile(sys.argv[1]) print 'Script %s has run' % sys.argv[1] FILE PyLaunch.bat ------------------------------------ C:\APPS\jython-2.1\jython.bat -i PyEnv.py %1 %2 %3 %4 %5 %6 %7 Then, to start up the interactive session with the help function present, just run the bat file: C:\temp>PyLaunch.bat C:\temp>C:\APPS\jython-2.1\jython.bat -i PyEnv.py help(help) help([,subject]) -> None Put your high level help documentation goes here: List of environments variables, functions, etc. If you set up resources like database connections, be sure to use a try/finally construct in PyEnv.py to clean up after exceptions. Good luck, Clark -----Original Message----- From: Satya Ghattu [mailto:sg...@be...] Sent: Thursday, July 17, 2003 6:04 PM To: 'jyt...@li...' Subject: [Jython-Users] Defining commands in the shell .... Hello there... I am not sure if this is achievable in Jython interactive shell but would like to know for sure ... Can I define 'commands' in jython that I can execute when a user types it on the interactive shell? For example, I would like to define a 'help' command that shows the user some basic help about my application. So, the user can just type, >>> help on the command prompt. And also can these commands take additional arguments, like ... >>> help connection which should display help about connecting to my application. Thanks for any help, -satya ------------------------------------------------------- This SF.net email is sponsored by: VM Ware With VMware you can run multiple operating systems on a single machine. WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the same time. Free trial click here: http://www.vmware.com/wl/offer/345/0 _______________________________________________ Jython-users mailing list Jyt...@li... https://lists.sourceforge.net/lists/listinfo/jython-users |