Back to index

salome-geom  6.5.0
Functions
addvars2notebook_GEOM Namespace Reference

Functions

def addvars2notebook

Function Documentation

def addvars2notebook_GEOM.addvars2notebook (   filename,
  vars_and_values 
)

Definition at line 20 of file addvars2notebook_GEOM.py.

00020 
00021 def addvars2notebook(filename, vars_and_values):
00022     stream = open(filename)
00023     lines = stream.readlines()
00024     stream.close()
00025     newlines = []
00026     for line in lines:
00027         if line.find("= geompy.") >= 0:
00028             name = line.split('=')[0]
00029             name = name.strip()
00030             vals = line
00031             fields = vals.split("(")
00032             if len(fields) == 2:
00033                 begin = fields[0] + "("
00034                 vals = fields[1]
00035                 fields = vals.split(")")
00036                 if len(fields) == 2:
00037                     vals = fields[0]
00038                     end = ")" + fields[1]
00039                     vals = vals.split(',')
00040                     newline  = begin
00041                     newvals = []
00042                     for i in range(len(vals)):
00043                         valname = name + "_val_%s"%(i+1)
00044                         val = vals[i]
00045                         vvv = val.strip()
00046                         try:
00047                             iii = int(vvv)
00048                             vars_and_values.append([valname, val])
00049                             val = val.replace(vvv, valname.__repr__())
00050                         except ValueError:
00051                             try:
00052                                 fff = float(vvv)
00053                                 vars_and_values.append([valname, val])
00054                                 val = val.replace(vvv, valname.__repr__())
00055                             except ValueError:
00056                                 pass
00057                             pass
00058                         newvals.append(val)
00059                         pass
00060                     newline += ','.join(newvals)
00061                     newline += end
00062                     line = newline
00063                     pass
00064                 pass
00065             pass
00066         newlines.append(line)
00067         pass
00068     content = "".join(newlines)
00069     return content