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

Posted on 2008-11-07
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\", line 13, in <module>
    text = it.GetFormattedText(True, 80)
  File "c:\extras\prog\python25\lib\site-packages\win32com\client\", 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

    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

    How about simply getting the NotesRichTextItem instead of a NotesItem?

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    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 while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now