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

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')
ns.Initialize()
 
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

SistemasRoyalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill-HansonCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SistemasRoyalAuthor Commented:
How about simply getting the NotesRichTextItem instead of a NotesItem?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.