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


Reply via email to