Search code examples
pythonpython-2.7pyvmomi

Should I be concerned about return "(str) ['item1', 'item2' ]"


I'm trying to return a list in one of my methods for interacting with vmware via pyvmomi.

active_list = self.vss.spec.policy.nicTeaming.nicOrder.activeNic

when I do return active_list I get:

(str) [
   'vmnic0',
   'vmnic1'
]

Type:

type(active_list)
<class 'pyVmomi.VmomiSupport.str[]'>

Since I'm able to iterate over the active_list as it is, shoud I be concerned about the (str) prefix.

I was able to avoid the (str) [...] prefix by coping active_list, new_list=list(active_list)

What is the best pythonic approach to this?


Solution

  • This (str) prefix comes from the __str__() representation of the <class 'pyVmomi.VmomiSupport.str[]'>. Obviously the class also supports iterating, so you can loop over it.

    You can learn more about special method names in the Docs.

    As long as you don't rely on the str() output of that class / instance you can ignore it.