I'm new to Python so the answer to this question is probably easy. I've done some coding in it before, but I forgot most of it.
I have an list of values, that I get from a file like this:
podela = fobj.read().split()
There are 10 values that as a whole represent some data. These 10 values repeat N times. So, Nx10 values all together. Only some values (4 out of 10) are used to create an instance of the following class.
I have a class that represents time:
class Vreme:
day = 0
hour = 0
minute = 0
second = 0
def __init__(self, day, hour, minute, second):
self.day = day
self.hour = hour
self.minute = minute
self.second = second
def __init__(self):
self.day = 0
self.hour = 0
self.minute = 0
self.second = 0
def toString(self):
s = repr(self.day)+'-'+repr(self.hour)+':'+repr(self.minute)+':'+repr(self.second)
return s
def print(self):
s = self.toString()
print(s)
How can I instantiate a list of instances of Vreme using the list podela?
EDIT1: podela holds the values, which are hex representations in a string format.
Part of the file example, 4xlines:
4a 02 f6 01 00 04 0e 08 03 00
4a 02 f6 01 00 04 0e 08 04 00
49 02 f6 01 00 04 0e 08 04 00
49 02 f5 01 00 04 0e 08 04 00
4a 02 f6 01 00 04 0e 08 05 00
podela after split, few last values:
'0e', '12', '1f', '00', '49', '02', 'f4', '01', '00', '04', '0e', '12', '20', '00', '49', '02', 'f5', '01', '00', '04', '0e', '12', '20', '00', '48', '02', 'f4', '01', '00', '04', '0e', '12', '20', '00', '4a', '02', 'f4', '01', '00', '04', '0e', '12', '21', '00', '49', '02', 'f5', '01', '00', '04', '0e', '12', '21', '00', '4a', '02', 'f5', '01', '00', '04', '0e', '12', '22', '00', '49', '02', 'f5', '01', '00', '04', '0e', '12', '22', '00', '48', '02', 'f4', '01', '00', '04', '0e', '12', '22', '00', '4a', '02', 'f6', '01', '00', '04', '0e', '12', '23', '00', '48', '02', 'f4', '01', '00', '04', '0e', '12', '23', '00']
Input file (that gets split for podela) is 56kB, but this is a test file. Real files will be 5MB+
EDIT2: Example of input and output Example is with a really small file, that holds 3x10 values.
The file holds these values:
00 00 00 00 00 00 00 00 00 00
01 02 03 04 05 06 07 08 09 10
11 11 11 11 11 11 11 11 11 11
When podela is made, each of these values is a member of an array
podela = [00 00 00 00 00 00 00 00 00 00 01 02 03 04 05 06 07 08 09 10 11 11 11 11 11 11 11 11 11 11]
Lets say that I use values at positions 0, 2, 4 and 8 for a constructor. vreme should be a list of 3 instances of Vreme:
vreme[0] = 00 00 00 00
vreme[1] = 01 03 05 07
vreme[2] = 11 11 11 11
podelalook like? Post a sample please.__init__methods?