[python-win32] Re: Desire information about Invoke and InvokeTypes

Thomas Heller theller at python.net
Wed Apr 21 02:40:40 EDT 2004


>> > Is it possible you are tripping over us calling the 'default'
>> > method or property in some cases?  eg:, I could imagine:
>> >
>> > sc = chart.SeriesCollection()
>> > n = sc.Add(series_range, seriesAddDirection)
>> > print n
>> >
>> > would print '1' in certain cases.  However:
>> > print repr(n)
>> >
>> > Would make it more obvious.  It is possible the object has a
>> > 'default' property that is called whenever str() or int() is called
>> > on the object.
>>
>> I also was bugged by this behaviour some time ago.  Confusing, imo.
>
> Yes, I tend to agree, but am stuck between a rock and a hard place.

> Many samples, especially VB based ones often show code like:
>
> f = whatever.GetField()
> MsgBox "The field " & field & " has value " & field.Value
>
> Or even passing the object to a function that expects a string.  They
> make no reference at all to what the "implied" attribute name they are
> using is, or when passing as a param, make no reference to the
> behaviour.

> I believe Excel Cells and many other objects work this way, and COM
> goes to lengths to define the semantics.  Just like COM's
> INVOKE_PROPERTYPUTREF, it is one of those things that I would prefer
> didn't exist, but feel I can't ignore them given they do.

I didn't want to criticize you, the design decisions you made ;-).  It
seems a lot of this stuff (or even the COM semantics) is influenced by
the way it works in VB.

I am just thinking that it *could* make more sense (in ctypes.com) to be
more explicit.  So the above VB code would translate to ctypes.com:

f = whatever.GetField()
MessageBox("The field %s has value %d" (field.Item, field.Value))

Or something like that.

Thomas




More information about the Python-win32 mailing list