How can I access the NotesRichTextItem methods of a item retrieved using GetFirstItem from a Python script?

Posted on 2008-11-07
Medium Priority
Last Modified: 2013-12-18
I'm accesing a Notes database from a Python script using COM, using the code below. When I run it I get the following traceback:

Traceback (most recent call last):
  File "C:\Extras\Datos\Scripts\Python\Notes\testitem.py", line 13, in <module>
    text = it.GetFormattedText(True, 80)
  File "c:\extras\prog\python25\lib\site-packages\win32com\client\__init__.py", line 454, in __getattr__
    raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self), attr)
AttributeError: '<win32com.gen_py.Lotus Domino Objects.IItem2 instance at 0x188795360>' object has no attribute 'GetFormattedText'

I see I'm getting a generic NotesItem. Is there a way to retrieve the item as a NotesRichTextItem instead, or to allow the use of this last class' methods on the retrieved item?

from win32com.client import Dispatch
ns = Dispatch('Lotus.NotesSession')
mailsvr = ns.GetEnvironmentString('MailServer', True)
dbdir = ns.GetDbDirectory(mailsvr)
mail = dbdir.OpenMailDatabase()
vw = mail.GetView('($Inbox)')
doc = vw.GetLastDocument()
it = doc.GetFirstItem('Body')
text = it.GetFormattedText(True, 80)
print text

Open in new window

Question by:SistemasRoyal
LVL 22

Accepted Solution

Bill-Hanson earned 750 total points
ID: 22908087
First, the GetFormattedText method is misleading.  It does not return formatted text, just the plain text with tabs replaced by spaces.  I've never used it.  Instead, I just use the Text property (which is a member of both item classes).

text = it.Text

Unfortunately, there's no good way to get true formatted text from a NotesRichTextItem (even using LotusScript).  The only way that I know of is by using the C API, and even that is not very accurate.

Author Comment

ID: 24062242
How about simply getting the NotesRichTextItem instead of a NotesItem?

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question