Hi, I can see now that the parameter types are different. The Markets item method takes an integer and the Stocks method takes a variant.
According to the win32com docs, http://oreilly.com/catalog/pythonwin32/chapter/ch12.html#24074, PythonWin will map python types to a variant automagically, so it should just work. Perhaps this is an issue with late binding, and that I should force it to use early binding? Any ideas anyone? Thanks Peter. --- In [email protected], "pwa72x" <peter.aberl...@...> wrote: > > Hi, > > I'm using Python and the PyWin32 extensions to allow COM iterop with AB. > > I'm trying to call the Item method on a Stocks object, but I'm getting the > error below. > Confusingly, doing the same thing on the Markets object works fine. Can > anyone suggest what is happening here? > > Thanks > Peter > > ################################################ > import win32com.client > > def doWork(): > ab = win32com.client.Dispatch("Broker.Application") > > bLoadLSE = ab.LoadDatabase("E:\data\AmiBroker\Amibroker_databases\LSE"); > if bLoadLSE == False: > print "Could not load the LSE database" > return > > nNumMarkets = ab.Markets.Count > print "\nNumMarkets is %d " % nNumMarkets > for nMarketIdx in range(nNumMarkets): > currMarket = ab.Markets.Item(nMarketIdx) > print currMarket.Name > > nNumStocks = ab.Stocks.Count; > print "\nNumStocks is %d " % nNumStocks > for nStockIdx in range(nNumStocks): > print "StockIdx is %d" % nStockIdx > currStock = ab.Stocks.Item(nStockIdx) # <---- fails here > print currStock.Ticker > > if __name__ == "__main__": > doWork() > > ################################################ > > Output: > E:\data\python>python posting.py > > NumStocks is 714 > StockIdx is 0 > Traceback (most recent call last): > File "posting.py", line 25, in <module> > doWork() > File "posting.py", line 21, in doWork > currStock = ab.Stocks.Item(nStockIdx) # <---- fails here > TypeError: 'NoneType' object is not callable >
