ABSData.py
68 lines
| 2.4 KiB
| text/x-python
|
PythonLexer
|
r196 | ''' | |
Created on Jun 3, 2013 | |||
@author: Jose Antonio Sal y Rosas Celi | |||
@contact: jose.salyrosas@jro.igp.gob.pe | |||
''' | |||
class ABSData(object): | |||
__scriptName = "ABSData.py" | |||
def __init__(self): | |||
pass | |||
|
r197 | def convertStringtoList2(self, strData): | |
if strData != "" or strData != "None" or strData != None: | |||
lines = strData.split("],[") | |||
listData = [[0 for i in range(8)] for j in range(8)] | |||
for i,line in enumerate(lines): | |||
if i == 0: | |||
lines[i] = line.replace("[[","") | |||
if i == len(lines)-1: | |||
lines[i] = line.replace("]]","") | |||
elements = lines[i].split(",") | |||
for j,element in enumerate(elements): | |||
listData[i][j] = element | |||
else: | |||
listData = [["0","0","0","0","0","0","0","0"],\ | |||
["0","0","0","0","0","0","0","0"],\ | |||
["0","0","0","0","0","0","0","0"],\ | |||
["0","0","0","0","0","0","0","0"],\ | |||
["0","0","0","0","0","0","0","0"],\ | |||
["0","0","0","0","0","0","0","0"],\ | |||
["0","0","0","0","0","0","0","0"],\ | |||
["0","0","0","0","0","0","0","0"]] | |||
|
r196 | ||
return listData | |||
|
r197 | ||
def convertStringtoList1(self, strData): | |||
if strData != "" or strData != "None" or strData != None: | |||
lines = strData.split(",") | |||
for i,line in enumerate(lines): | |||
if i == 0: | |||
lines[i] = line.replace("[","") | |||
if i == len(lines)-1: | |||
lines[i] = line.replace("]","") | |||
else: | |||
lines = ["0","0","0","0"] | |||
return lines | |||
|
r196 | ||
def printList(self, listData): | |||
print listData | |||
|
r197 | ||
|
r196 | if __name__ == '__main__': | |
|
r197 | strData = "[[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],[1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0]," \ | |
"[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5]," \ | |||
"[1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5]," \ | |||
"[1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5]]" | |||
txtUes = "[0.533333,0.00000,1.06667,0.00000]" | |||
|
r196 | ||
data = ABSData() | |||
|
r197 | listData = data.convertStringtoList2(strData) | |
listUes = data.convertStringtoList1(txtUes) | |||
data.printList(listData) | |||
data.printList(listUes) |