class Portfolio:
def read(self, pathfilename):
.... stuff ....
self.portfolio[comp_symbol] = {'name': comp_name , 'holdings': comp_holdings}
def save_portfolio(self, port_collection):
port_collection.insert(self.portfolio)
def list_tickers(self):
return (self.portfolio.keys())
def __init__(self):
self.portfolio = {}
self.id = None
Here is how to call it:
port = Portfolio()
print "==================================================================================="
print port.id
print port.portfolio
print "==================================================================================="
port.read(portfolio_file)
print port.id
print port.portfolio
print port.portfolio.keys()
print "==================================================================================="
print port.list_tickers()
port.save_portfolio(port_collection)
print port.list_tickers()
print port.portfolio
The problem is that on performing the insert with pymongo, the property called portfolio changes, and there is an extra key added. For example: print port.list_tickers()
is different before and after the insert procedure and I do not see why this should be the case. Before the insert, I get ['CSCO', 'RSA', 'ARO']
and after the insert, I get: ['CSCO', 'RSA', '_id', 'ARO']
, but I should still be reading from the same class property. The additional _id
is obviously the id from MongoDB.