This chapter describes how to use the Jython Shell created by LeoUser.
The completion list shows the best prefix entered after the '.' Any other key withdraws the autocompleter.
This keystroke has two meanings:
Executing will dynamically expand a prefix to matching words already entered within the interpreter. For example: cactus cac( keystroke ) will expand cac to cactus. This will cycle through all matches to cac within the buffer upon repeated execution.
Typing a reference name followed by a ? will create a object view which gives the user a variety of information about the Object in question. Example:
a = 'meoooowwww' a? # Upon Enter, a panel will appear below showing Object information.
Typing ! at the command prompt followed by the system command you wish to execute will start the command as a process and return a JPID for the process that can be manipulated by the magic command set.
Entering one of the following commands will cause its corresponding command to execute:
%alias anAlias defines alias name as an alias for cmd. Afterwards, typing alias name params will execute the system command cmd params (from your underlying operating system). Aliases have lower precedence than magic functions and Python normal variables, so if foo is both a Python variable and an alias, the alias can not be executed until you remove the Python using del foo.
Toggles autocalling off and on. Autocalling is the ability to do something like:
dir a
instead of dir( a ).
Toggles autoindenting off and on.
Runs a method/function in a background thread. For example:
%bg doit()
This executes doit in a thread. The status of the operation can be seen by looking at the jobs object:
jobs.status() #Prints the status of the jobs.
Alternatively you can access the status like so:
jobs[jobnumber].result
jobnumber is printed out when the method/function is about to execute. The result will be the return value of the method/function or it will tell you the job isn't finished yet.
Changes the current working directory of the Jython Shell. .. signifies the parent directory. Absolute and relative paths are allowed.
Destroys all JPIDs.
Clears the shell of all text and starts over with a fresh prompt.
Shows the current working directory of the Jython Shell.
Sets the reference to a java.io.File instance representing the current directory.
Deserialize an Object stored on disk into the reference.
Same as %edit.
Brings up the Jython Shell editor and executes the resulting code.
This command allows you to conveniently edit multi-line code right in your JythonShell session. If called without arguments, %edit opens up an empty editor with a temporary file and will execute the contents of this file when you close it (don t forget to save it!). Options:
-p | Calls the editor with the same data as the previous time it was used, regardless of how long ago (in your current session) it was. |
-x | Suppresses execution of the edited code upon exit. This is mainly useful if you are editing programs which need to be called with command line arguments, which you can then do using %run. |
If args are given, the following possibilities exist:
Prints all environment variables.
Prints all or part of the history. If given, the -n argument signifies that line numbers should not be printed out.
Destroys JPID n.
Shows the contents of the current working directory.
Shows a java array of File instances. For example:
%ls a # a now holds a java array of File instances
Returns the current available set of magic commands.
Defines a macro that can be executed by using the name given. For example:
%macro macex 9:10 11 12:13 4
creates a macro called macex and puts line 9-10, 11 12-13 and 4 from the history into it Hence entering macex and typing enter will cause those lines to rexecute.
To see the contents of the macro type: print macroname. To remove a macro type: del macroname.
Same as 'print'.
%pdb filename
Runs the file under Pdb in the shell.
Toggles automatic startup of Pdb on an exception. Examples:
%pdb on --> now on %pdb off --> now off %pdb 1 --> now on %pdb 0 --> now off
Prints out the doc string of the passed in object if one can be found, otherwise does nothing.
The object may be a module, a method, an object, etc.
Attempts to locate the source file of the passed in object and displays the contents of the source in the shell.
An alias for the ? object viewer syntax. If the references is valid, a widget containing info on the reference will appear.
Executes a statement entered on the same line in the profile module.
Puts a java Set of Processes in the reference. For example:
%ps a #a now holds a Set of Processes.
Repeats the last input.
Resets the namespace by removing all names defined by the user. Input/Output history remain in case you need them.
Runs the named file inside IPython as a program. Options:
Suppresses setting __name__ to __main__. Instead, sets __name__ to the file's name without extension (as Python does under import).
This allows running scripts and reloading the definitions in them without calling code protected by:
if __name__ == __main__:
This command uses the same syntax as %macro for line extraction, but instead of creating a macro it saves the resulting string to file whose name is given. It ensures the filename ends with a .py extension, and it asks for confirmation before overwriting existing files.
Runs the given command using command.getoutput() and updates the user's interactive namespace with a variable called varname containing the value of the call. Your command can contain shell wildcards, pipes, etc. The = is mandatory, and the variable name must be a valid Python identifier. Options:
Sends the reference as input to JPID n.
Saves the object referenced by reference as a serialized Object.
Places the reference into the editor if the reference is a JComponent subclass. Useful for quick gazing of what a Swing component looks like.
Runs the given command using commands.getoutput(), and returns the result formatted as a list (split on). The output is stored in ipython's regular output cache Out[N] and in the N automatic variables.
Shows the threads running and the state they are in. Selecting a thread shows the thread's stack.
Removes the given alias.
Loads data from a url into a reference. For example:
%url a http://python.org
take the data at http://python.org and places it in ref.
Suspends the JythonShell until JPID n has finished.
Prints the list of identifiers that have been defined interactively.
Returns a sorted list of all interactive variables. If arguments are given, only variables of types matching these arguments are returned. Examples:
%who_ls %who_ls str int #this prints out variables whose type is str and int
Prints a table of identifiers that have been defined interactively.
Transforms reference ref2 with the stylesheet in ref1 putting the result in ref3.
JPIDs are not PIDs of the OS. They are a system by which the JythonShell can keep track of Processes created by it, and means by which the user can manipulate those Processes.
The CWD does not indicate what the process is working in. It is intended to function with the Magic Commands. This system does not interoperate with java.io.File or Jython open. To achieve interoperability the user should use the magic command of the form:
%cwd reference
This will place a java.io.File in the reference. The File instance is a copy of the CWD File and will allow the user to open, write, create, close streams and such in the JythonShell's CWD