Python persisting function result in a module -


i refactoring code use different input data sources, using proxy module calls different data sources (lets prices, returns equities) details.

i writing data getters in modules going called proxy class. expected have several such modules working. lets module contains 3 functions 3 fields a,b , c. modules return dict object proxy file in turn returns dict main file.

the main file call proxy file computations call proxy b , more computations calls proxy c. since a,b,c go same data source (there multiple sources stay consistent getting data in sense if using bloomberg use bloomberg b , c or if use reuters use reuters b , c also)

i want able create a,b , c dictionaries when request comes module. have problem although can create a,b , c, dont know how store b , c dicts in proxy class or in appropriate module after calculating dict object or when request b comes not have send request module again.

i not have this, there no difference in terms of efficiency or space complexity, wondering how this.

so far have seen storing data file using json/pickling , reading want better solution without file i/o.

mainfile.py:

import proxy p a_data = p.getdata(a) ... b_data = p.getdata(b) ... c_data = p.getdata(c) 

proxy.py:

import data_source.bberg b import data_source.reut r  def getdata(data_type):   #defaulting b demonstration, data_type or b or c   if data_type == a:      return b.geta()   if data_type == b:      return b.getb()   if data_type == c:      return b.getc() 

bberg.py:

def geta():      details = {}      ... # fill details      return details   # similar implementations getb() , getc(), return dict object 

i want make code behaves this

    a_global = {}     b_global = {}     c_global = {}     if data_type == a:        a_global =  b.geta()        b_global = b.getb()        c_global = b.getc()    # a,b , c populated , when `getdata(b)` called should return `b_global` , not go bberg.py  

this way wrong wondering if can make a_global, b__global persist between calls getdata(datatype)

structure:

app/  mainfile.py  proxy.py   data_source/     bberg.py   reut.py  


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -