Hi
I'm implementing a few COM classes using Python. I've come across a
problem when I'm trying the return an instance of a class from a
method on one of my classes. The code is as follows, with two classes
- clsDividend and clsDividendEsimate. The
clsDividend.GetDividendEstimates method tries to return a new instance
of the clsDividendEstimate class, but throws an error.
Any ideas what I'm doing wrong - is it possible to do what I'm trying
to achieve?
The client will ultimately be Excel, but I can't even get it to work
within a Python client yet. Ultimately I'd like to do this in my
client(pseudo):
oDiv = CreateObject("SBLFront.clsDividend")
oDivEst = oDiv.GetDividendEstimates("testval")
msgbox oDivEst.ccy
Many thanks
Paul
# Expose the Python SBLFront.
class clsDividend(clsSBLFront):
"""The SBLFront object exposed via COM
"""
#_reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER
_public_methods_ = ['GetDividendEstimates']
_public_methods_.extend(clsSBLFront._public_method s_)
# All registration stuff to support fully automatic
register/unregister
_reg_verprogid_ = "SBLFront.clsDividend.1"
_reg_progid_ = "SBLFront.clsDividend"
_reg_desc_ = "Python SBLFront"
_reg_clsid_ = "{2E851A1B-A8D1-4AD5-BA16-EB6B9BCF2F21}"
_reg_class_spec_ = "win32com.servers.sblfront.clsDividend"
# ------------------------------------------------------------------------
def __init__(self):
clsSBLFront.__init__(self)
self.dict = {}
def GetDividendEstimates(self, InsId):
oDivEst = clsDividendEstimate('USD', 1.0, 1.0,
'2003-01-01','2003-01-01','2003-01-01','Test description')
return oDivEst
# ----------------------------------------------------------------------------
class clsDividendEstimate:
"""The SBLFront object exposed via COM
"""
_public_methods_ = []
_public_attrs_ = ['ccy', 'dividend', 'tax_factor', 'pay_day',
'ex_div_day', 'day', 'description']
_readonly_attrs_ = ['ccy', 'dividend', 'tax_factor', 'pay_day',
'ex_div_day', 'day', 'description']
# All registration stuff to support fully automatic
register/unregister
_reg_verprogid_ = "SBLFront.clsDividendEstimate.1"
_reg_progid_ = "SBLFront.clsDividendEstimate"
_reg_desc_ = "Python SBLFront"
_reg_clsid_ = "{055DEFBC-B095-4C5B-A9CE-BFBB965BBDC1}"
_reg_class_spec_ = "win32com.servers.sblfront.clsDividendEstimate "
# ------------------------------------------------------------------------
def __init__(self):
self.dict = {}
self.ccy = ''
self.dividend = 0.0
self.tax_factor = 0.0
self.pay_day = ''
self.ex_div_day = ''
self.day = ''
self.description = ''
def __init__(self, sCCY, dDiv, dTax, dtDay, dtPayDay, dtExDivDay,
sDesc):
self.dict = {}
self.ccy = sCCY
self.dividend = dDiv
self.tax_factor = dTax
self.pay_day = dtPayDay
self.ex_div_day = dtExDivDay
self.day = dtDay
self.description = sDesc 1 1877
I managed to solve my own problem - it didn't like having two __init__
methods (different prototypes).
However, I have another problem. I've worked out how to return a
list, and also how to return an instance of a class. I know need to
be able to return a list of objects. Is this possible (no luck so
far)?
Paul pa*******@standardbank.com (Paul) wrote in message news:<bb**************************@posting.google. com>... Hi
I'm implementing a few COM classes using Python. I've come across a problem when I'm trying the return an instance of a class from a method on one of my classes. The code is as follows, with two classes - clsDividend and clsDividendEsimate. The clsDividend.GetDividendEstimates method tries to return a new instance of the clsDividendEstimate class, but throws an error.
Any ideas what I'm doing wrong - is it possible to do what I'm trying to achieve?
The client will ultimately be Excel, but I can't even get it to work within a Python client yet. Ultimately I'd like to do this in my client(pseudo):
oDiv = CreateObject("SBLFront.clsDividend") oDivEst = oDiv.GetDividendEstimates("testval") msgbox oDivEst.ccy
Many thanks Paul
# Expose the Python SBLFront. class clsDividend(clsSBLFront): """The SBLFront object exposed via COM """ #_reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER _public_methods_ = ['GetDividendEstimates'] _public_methods_.extend(clsSBLFront._public_method s_)
# All registration stuff to support fully automatic register/unregister _reg_verprogid_ = "SBLFront.clsDividend.1" _reg_progid_ = "SBLFront.clsDividend" _reg_desc_ = "Python SBLFront" _reg_clsid_ = "{2E851A1B-A8D1-4AD5-BA16-EB6B9BCF2F21}" _reg_class_spec_ = "win32com.servers.sblfront.clsDividend"
# ------------------------------------------------------------------------
def __init__(self): clsSBLFront.__init__(self) self.dict = {}
def GetDividendEstimates(self, InsId): oDivEst = clsDividendEstimate('USD', 1.0, 1.0, '2003-01-01','2003-01-01','2003-01-01','Test description') return oDivEst
# ----------------------------------------------------------------------------
class clsDividendEstimate: """The SBLFront object exposed via COM """ _public_methods_ = [] _public_attrs_ = ['ccy', 'dividend', 'tax_factor', 'pay_day', 'ex_div_day', 'day', 'description'] _readonly_attrs_ = ['ccy', 'dividend', 'tax_factor', 'pay_day', 'ex_div_day', 'day', 'description']
# All registration stuff to support fully automatic register/unregister _reg_verprogid_ = "SBLFront.clsDividendEstimate.1" _reg_progid_ = "SBLFront.clsDividendEstimate" _reg_desc_ = "Python SBLFront" _reg_clsid_ = "{055DEFBC-B095-4C5B-A9CE-BFBB965BBDC1}" _reg_class_spec_ = "win32com.servers.sblfront.clsDividendEstimate "
# ------------------------------------------------------------------------
def __init__(self): self.dict = {} self.ccy = '' self.dividend = 0.0 self.tax_factor = 0.0 self.pay_day = '' self.ex_div_day = '' self.day = '' self.description = ''
def __init__(self, sCCY, dDiv, dTax, dtDay, dtPayDay, dtExDivDay, sDesc): self.dict = {} self.ccy = sCCY self.dividend = dDiv self.tax_factor = dTax self.pay_day = dtPayDay self.ex_div_day = dtExDivDay self.day = dtDay self.description = sDesc This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Grzegorz Staniak |
last post by:
Hello,
I'm a newbie Python user, a systems administrator - I've been trying
to switch from Perl to Python for administrative tasks - and one thing
I cannot understand so far is why I need the...
|
by: Robert |
last post by:
Python doesn't know the class of a method when container not direct
class attribute:
>>> class X:
.... def f():pass
.... g=f
.... l=
....
>>> X.g
<unbound method X.f>
|
by: Neil Zanella |
last post by:
Hello,
I would like to know whether it is possible to define static class methods
and data members in Python (similar to the way it can be done in C++ or Java).
These do not seem to be mentioned...
|
by: John M. Gabriele |
last post by:
I've done some C++ and Java in the past, and have recently learned
a fair amount of Python. One thing I still really don't get though
is the difference between class methods and instance methods. I...
|
by: Graham |
last post by:
This has to do with class variables and instances variables.
Given the following:
<code>
class _class:
var = 0
#rest of the class
| |
by: Sylvain Ferriol |
last post by:
hello
can you explain why python does not see difference between instance
method and class method, having the same name
example
.... def f(self):
.... print('instance method')...
|
by: vbgunz |
last post by:
I remember learning closures in Python and thought it was the dumbest
idea ever. Why use a closure when Python is fully object oriented? I
didn't grasp the power/reason for them until I started...
|
by: Agustin Villena |
last post by:
Hi!
is there anyway to show the class of a method in an exception's
traceback?
For example, the next code
class Some(object):
def foo(self,x):
raise Exception(x)
|
by: Hussein B |
last post by:
Hi,
I'm familiar with static method concept, but what is the class method?
how it does differ from static method? when to use it?
--
class M:
def method(cls, x):
pass
method =...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |