|
|
|
|
|
|
|
|
|
|
|
|
|
|
Using Python to create a command line interpreter for Notes (continued)
Python has identical syntax for calling Notes objects by either method. Using PythonWin, the commands required are:
import win32com.client
sess=win32com.client.Dispatch("Lotus.NotesSession")
|
Typing the above on its own will use late-bound COM. To use early-bound, there's a Python script called "make.py" built into PythonWin that will configure Python for any available COM class. To make it even easier, PythonWin includes this in the standard menu. To use it with Notes, select "Lotus Domino Objects" from the list offered. Once make.py has been run, all calls to those objects will use the more efficient early-bound COM calls.
If you wish to automate this process of registering the Domino classes, perhaps as part of a Python program interfacing to Notes, then put the following lines in your code:
from win32com.client import gencache
gencache.EnsureModule('-2EED-1069-BF5D-00DD011186B7}', 0, 1, 0)
|
Since Python now knows all about the Notes objects, PythonWin can also give you the same helpful pop-up class boxes for Notes as it does for internal Python classes. Figure C shows the box that appears when the NotesSession object "sess" is typed in.
FIGURE C
 
Pop-up class browser is a standard part of PythonWin. Roll over picture for a larger image.
Once the "sess" object is defined, it's possible to use a much more familiar syntax to call other objects. In this example, a database is opened and the title is examined and changed:
>>> db=sess.GetDatabase("","log.nsf")
>>> db.Title
u'Notes Log'
>>> db.Title='Notes Log (Python)'
>>> db.Title
u'Notes Log (Python)'
|
There are three things to note from this example:
- Python lets you omit the print statement to examine an object;
- Notes returns strings as Unicode rather than plain ASCII while Python has simple functions to switch between these;
- It's only possible to create one new Notes object using COM (whether you use Visual Basic, Python, or any other language), and that's the NotesSession.
The objects which are typically created using a "Dim New" statement in LotusScript, such as NotesDatabase, are created instead using methods of NotesSession.
Using Java PythonWin is just one of many implementations of Python on various platforms. One recent addition is the Java based JPython. This is supplied as a JAR file of 100% Pure Java code. It enables a Python interpreter to operate within any JVM (Java Virtual Machine) on any system, or for a Java applet on a Web page to execute Python script code rather than Java.
Like PythonWin, JPython is both a command line interpreter and a full language interpreter, with the difference that now you have all the Java classes--Swing, JDBC (Java Data Base Connectivity), Domino, LotusXSL and thousands of others--available to browse and play with on the command line. And unlike COM, this will run on Linux, Solaris, Macintosh, or any other Java supporting platform.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Advertisement --
Learn Notes and Domino 8 at your place and pace!
Learn Notes and Domino in your office and/or home! TLCC's highly acclaimed distance learning courses for users, developers, and admins will enhance your career and your resume.
The many included activities and demos will make you a pro! Expert instructor help is a click away.
Click here to try a FREE demo course!! |
-- Advertisement --
Mark your calendar for in-depth Lotus training, May 12-14, Boston
Join experts and peers May 12-14 in Boston for educational and networking events that deliver real-world Lotus training so you can increase productivity and efficiency in your company, advance your skills, and squeeze the most from your current environment. One registration gets you into THE VIEW's Admin2010 and Lotus Developer2010.
Register by April 10 to save $200. |
|
|
|
|
|
|
|
|
|
|