Here is another example in context:

>>> import win32com.client
>>> td = win32com.client.Dispatch("TDApiOle80.TDConnection.1")
>>> td.InitConnectionEx( "http://myserver.com:8080/qcbin/"; )
>>> td.ConnectProjectEx("TM_PLAY_AREA", "TM_PlayArea", "user", "passwd")
>>> bfact = td.BugFactory
>>> mybug=bfact.Item(22)
>>> fields = mybug.Field("BG_DESCRIPTION")
>>> print fields
Test Set: Mercury Tours UI
Test: [1]Welcome Page
Run: Run_9-11_11-43-36
Step: Forms

Description:
Check the forms on the page:
    - Input fields
    - Lists
    - Radio buttons
    - Checkboxes

Expected result:
1. The input fields should be left aligned.

>>> mybug.Field("BG_DESCRIPTION")
u'Test Set: Mercury Tours UI\nTest: [1]Welcome Page\nRun: Run_9-11_11-43-36\nSte
p: Forms\n\nDescription:\nCheck the forms on the page:\n    - Input fields\n
- Lists\n    - Radio buttons\n    - Checkboxes\n\nExpected result:\n1. The input
 fields should be left aligned.\n2.'

>>> mybug.Field("BG_DESCRIPTION").Value = "123"
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'unicode' object has no attribute 'Value'


On 5/15/07, Michael March <[EMAIL PROTECTED]> wrote:
> Ok..  here is the VB example .. (this is for / provided by HP's
> Quality Center help file..)
>
> Sub LinkDefects()
>
> 'This example creates two defects and links them
>
>     Dim BugF As BugFactory
>
>     Dim Bug1 As Bug
>
> ' tdc is a TDConnection. The user is authenticated and
>
> ' connected to the project before this routine runs.
>
>     Set BugF = tdc.BugFactory
>
>
> 'Create new defects
>
>     Set Bug1 = BugF.AddItem(Null)
>
>     Bug1.Summary = "Lydia Bennet is 15 years old."
>
>     Bug1.Status = "New"
>
>     Bug1.Priority = "3-High"
>
>     Bug1.Field("BG_SEVERITY") = "3-High"
>    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     Bug1.DetectedBy = c_qcUser
>
>     Bug1.Field("BG_DETECTION_DATE") = Date
>     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     Bug1.Post
>
> I'm able to translate all that code, no prob, except for the lines 
> highlighted.
>
> If you do:
>
> print Bug1.Field
>
> ..you get the current value of the field.
>
> On 5/15/07, Tim Golden <[EMAIL PROTECTED]> wrote:
> > Michael March wrote:
> > > When you do:
> > >
> > >     object.Field("UserDefined_01")
> > >
> > > ... the output is a unicode object..  So putting:
> > >
> > >    object.Field("UserDefined_01").Value
> > >
> > > .. barfs..
> > >
> > > I'm obviously missing something here..
> >
> > Not seeing the exact code you're using, so I
> > could be wrong, but I would expect the result
> > of the expression: object.Field ("blah") to
> > be an instance of some class x.y.Field
> > (or whatever). Since you wouldn't be able to
> > use such a term on the LHS of a Python name-binding
> > (object.Field("UserDefined_01") = "Open") then
> > the first error you noted is unsurprising.
> >
> > I would then not be surprised if the pywin32
> > proxy for that field handled things like
> > __unicode__, __str__, __repr__ in such a way
> > as to return the ms-defined default property,
> > typically the one called .Value which could
> > well be a Unicode string.
> >
> > But obviously, if what you say above is strictly
> > true - that object.Field ("blah").Value "barfs"
> > (and I'm going to guess that this means: "raises
> > an AttributeError because the builtin Unicode
> > object has no .Value attribute) then what I'm
> > describing above isn't happening.
> >
> > But am I understanding correctly? Could you provide a
> > small code fragment which might help clarify things?
> >
> > Here's a toy example using Excel:
> >
> > <code>
> > from win32com.client.gencache import EnsureDispatch
> > xl = EnsureDispatch ("Excel.Application")
> > ws = xl.Workbooks.Add ().ActiveSheet
> >
> > cell_11 = ws.Cells (1, 1)
> > print cell_11.__class__
> > # win32com...Range
> >
> > cell_11 = "blah"
> > # has now bound cell_11 to the string "blah".
> > # It works, but isn't what we want. Rebind.
> >
> > cell_11 = ws.Cells (1, 1)
> > cell_11.Value = "blah"
> > # OK
> >
> > print cell_11
> > # "blah" because of the default property
> > print cell_11.Value
> > # "blah"
> >
> > x = cell_11
> > print x.__class__
> > # win32com...Range
> >
> > y = cell_11.Value
> > print y.__class__
> > # type "str"
> >
> > </code>
> >
> > TJG
> >
>


-- 
<admiral>

Michael F. March ----- [EMAIL PROTECTED]
Ph: (415)462-1910 ---- Fax: (602)296-0400
P.O. Box 2254 ---- Phoenix, AZ 85002-2254
          "Seriously" - HSR
_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to