Open amyasnikov opened 1 year ago
And another one example
import ttp
template = '''
<group name="interfaces" to_int="trunk_vlan">
interface {{ name }}
switchport trunk allowed vlan {{ trunk_vlan | split(',') }}
</group>
'''
data = '''
interface Ethernet0/1
switchport trunk allowed vlan 5,10,15
'''
parser = ttp.ttp(template=template, data=data)
parser.parse()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.10/site-packages/ttp/ttp.py", line 449, in parse
self.__parse_in_one_process()
File "/usr/local/lib/python3.10/site-packages/ttp/ttp.py", line 518, in __parse_in_one_process
parserObj.parse(groups_indexes=input_obj.groups_indexes)
File "/usr/local/lib/python3.10/site-packages/ttp/ttp.py", line 2628, in parse
RSLTSOBJ.make_results(self.vars, raw_results, main_results=self.main_results)
File "/usr/local/lib/python3.10/site-packages/ttp/ttp.py", line 2838, in make_results
if self.processgrp() is not False:
File "/usr/local/lib/python3.10/site-packages/ttp/ttp.py", line 3251, in processgrp
self.record["result"], flags = self._ttp_["group"][func_name](
File "/usr/local/lib/python3.10/site-packages/ttp/ttp.py", line 69, in __call__
return self._ttp_[self.parent_dir][self.function_name](*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/ttp/group/to_converters.py", line 21, in to_int
data[k] = int(v)
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
Maybe it's a misuse of to_int, but it will be very useful to get a list of integers from a list of strings via this clause.
Hello, thank you for raising this issue, both requests should be addressed in 0.9.5, feel free to test and let me know how it goes.
Updated documentation with an example of how to use intlist
variable to convert list of string into list of integers - https://ttp.readthedocs.io/en/latest/Groups/Functions.html#to-int
Python version: 3.10.12 TTP version: 0.9.4
Example of the error:
Expected behavior: TTP ignores the absence of "mask" key for Ethernet0/2 and outputs the result without an error