Issues about class initialialization in with large numerical data
Hi All, i am writing a class called communicate. Something like this: class Communicate: """ This is the main communicate class : there will be more """ def __init__(self): """This should hopefully read a file and set self's parameters """ self.C = 10 self.K = 6 self.N = 8 self.Na = 3 self.L = 4 self.modulation = "QPSK" 1. Shown is just one method in the class. Now there are lot of self variables (i understand they are something like private variables). Now i want to have an .ini file, so that i call something like this in the __init__ module : def __init__(self, fileName): file = open(fileName, 'r') self = something(file) and all the self's variables are set. i want the ini file to be the interface between the class and the outside world. Some one suggested ConfigParser , couldnt get an idea of what it is and how to use it.. 2. Is this method of having all the data in self variables good.The size of some of these 'self' could be very high 40000x40000 complex. Should i create local variables in the methods (i need a lot of variables, but their def life is too small .....) for example one of the method could be: def generateNoise(self): """ Generates AWGN """ power = Numeric.sqrt(RandomArray.random()*10) Noise = Numeric.zeros(....) Noise.real = Random ...... Noise.imag = RandomArray.... (Boared to type the whole thing that is why there are ......'s ) Any way power is a local variable, which i guess dies after generateNoise() method is called in the object. Am i right.. Can i have variables like 'power' 3. Thirdly, i want an easy method like '.mat' that exists in matlab. Can i use pickle (cPickle or Numeric.pickle) to store all the variables that i want. These matrices could be 40000x40000 entries long. Assuming that all the variables are in 'self' should i write an assignment module before pickling them (in case pickle is the right way to store these variables) def writeToFile(self): Na = self.Na x = self.x pickle the variables Na, x Thankx in advance and in anticipation, karthik PS: slowly moving from Matlab to Python, hence these stupid doubts ----------------------------------------------------------------------- Karthikesh Raju, email: karthik@james.hut.fi Researcher, http://www.cis.hut.fi/karthik Helsinki University of Technology, Tel: +358-9-451 5389 Laboratory of Comp. & Info. Sc., Fax: +358-9-451 3277 Department of Computer Sc., P.O Box 5400, FIN 02015 HUT, Espoo, FINLAND -----------------------------------------------------------------------
participants (1)
-
Karthikesh Raju