Hi i have unicode type characters
a = "épaisseur4/nominalvalue"
when append this to a lits i am getting like this
final = []
final.append(a)
print final
any way to fix this ?
Hi i have unicode type characters
a = "épaisseur4/nominalvalue"
when append this to a lits i am getting like this
final = []
final.append(a)
print final
any way to fix this ?
a = "épaisseur4/nominalvalue"
final = []
final.append(a)
print final
print final[0]
returns
['\xc3\xa9paisseur4/nominalvalue']
épaisseur4/nominalvalue
>>>
Does that get what you want? When you reference the string item it gets decoded properly.
There's nothing to fix.
When you print an array, it will print the repr()
of its elements. Which gives you that character code.
If you want to display the string representation instead, you can print them separately.
Or make your own list-type :
class Array(list):
def __str__(self):
elements_string = ', '.join(self)
return "[{}]".format(elements_string)
print Array(final)
print final
[épaisseur4/nominalvalue]
['\xc3\xa9paisseur4/nominalvalue']
How to pass Array(final) to a dataset?
when i pass this to dataset i am getting same errror
code i am using
event.source.parent.getComponent('Power Table').data = system.dataset.toDataSet(['Path'], [[x] for x in Array(final)])
I’ve set up an experiment transferring information from one power table to another in an effort to replicate your issue, but haven’t been successful.
Here is the script I used on a button:
class Array(list):
def __str__(self):
elements_string = ', '.join(self)
return "[{}]".format(elements_string)
final = []
dataSet = event.source.parent.getComponent('Power Table 1').data
for row in range(dataSet.rowCount):
final.append(dataSet.getValueAt(row, "Path"))
event.source.parent.getComponent('Power Table').data = system.dataset.toDataSet(['Path'], [[x] for x in Array(final)])
When I push the button, I get this result:
The array transfers correctly, so I’m not sure what the issue is. What is your input and expected result? Perhaps, I can adjust the experiment and help you figure this out.
I found the issue while appending to the list i need to do like this
final.append(unicode(tags))
If you’re going to iterate over the array, then there’s no point in having a custom class.
The whole point of it is to override the __str__
method, which is only callable on the array itself.
The elements you get when iterating are the same you’d get from a builtin python list.
I took the liberty of cleaning up the script a bit:
input_table = event.source.parent.getComponent('Power Table 1')
output_table = event.source.parent.getComponent('Power Table')
paths = input_table.data.getColumnAsList(x) # where x is the 0 based index of the column
output_table.data = system.dataset.toDataSet(['Path'], [[unicode(p)] for p in paths])
Two things to note:
Power Table
?edit: I don’t think the explicit unicode conversion is actually needed there, but I have no idea how vision tables treat things… I’d try without it first if I were you.
Your code is perfect, and will work just fine in Vision as long as x is correctly defined.