Hello,
In a python script I need to convert a number into text. (I do not want a node)
Could you give me the python encoding of this line?
My test line is:
Elif Lparam [i] == “Text”:
??
Did u try
str(variable)
Or
var.__str__()
Hi,
Thank you for your reply.
But I have an error on line 37 with this definition
Avertissement:IronPythonEvaluator.EvaluateIronPythonScript l'opération a échoué.
Traceback (most recent call last):
File "<string>", line 37, in <module>
UnicodeDecodeError: ('unknown', u'\xe9', 0, 1, '')
This is an encoding problem. I guess you have in your text parameter some funny character like "é, å ä"
instead of using str(“your parameter”) try using “your parameter”.encode(“latin_1”) or .encode(“utf8”).
Hi,
But I have an error on line 37 with this definition
elif Lparam[i] == "Text":
Sortie.append(LparamV[i].encode("utf8"))
or Sortie.append(LparamV[i].encode(“latin_1”))
Avertissement:IronPythonEvaluator.EvaluateIronPythonScript l’opération a échoué.
Traceback (most recent call last):
File “”, line 37, in
AttributeError: ‘float’ object has no attribute ‘encode’
Question: And if the value is already text, what happens?
Can you drop a dummy file here?
Hello,
In fact, the values come from an Excel file.
The problem is that sometimes a string value is recognized as a number.
So I make a test to know if the parameter should be a string and then convert it to string.
The value to be converted may be either a string or a number.
I think you can check that with isinstance (x, basestring)
Why this line does not work ?
Sortie.append(LparamV[i].encode(“utf8”))
My test is: elif Lparam[i] == “Text”:
I do not want to convert all the numbers.
It works on strings. Your error says you have a float
54/5000
I have a translation problem, do you have an example?
Ok Viktor,
You were right, it’s good
elif Lparam[i] == "Text":
if type(LparamV[i]) == str:
Sortie.append(LparamV[i])
else:
Sortie.append(str(LparamV[i]))
else:
Sortie.append(LparamV[i])