-1

I have a list like that


mylist
['\nms-0/0/0\n', '\nms-0/1/0\n', '\nms-0/2/0\n']

and I want to use every literal value of the list in a way that \n character is ignored:

Example:


for i in mylist:
     flows.xpath("//service-sfw-flow-count[interface-name=i]/flow-count//text()")

the value of "i" is not \nms-0/0/0\n but ms-0/0/0 , so I wonder if there is an option to use the literal value of every element of the list.

I've tried repr(i), but I got extra characters

"'\\nms-0/0/0\\n'"

Any idea ?

Regards

psagrera
  • 141
  • 1
  • 9

3 Answers3

0

Perhaps you can use

i.replace('\n', '')

to replace that characters with an empty string.

For example.

for i in mylist:
     new_i = i.replace('\n', '')
     flows.xpath("//service-sfw-flow-count[interface-name=i]/flow-count//text()")

On the other hand, if the i deflows.xpath is your variable, it may be advisable to make the following modification.

for i in mylist:
     new_i = i.replace('\n', '')
     flows.xpath(f"//service-sfw-flow-count[interface-name={new_i}]/flow-count//text()")
Luis
  • 133
  • 6
-1

try this:

mylist = [r'\nms-0/0/0\n', r'\nms-0/1/0\n', r'\nms-0/2/0\n']
print(mylist)

find more here

Maexchen
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 23 '22 at 13:34
-1

It was an issue with the xpath expression

new.xpath("//service-sfw-flow-count[interface-name='" + i + "']/flow-count//text()")
psagrera
  • 141
  • 1
  • 9