Question

# the lines below are iterating through TIBCO Spotfire tables, getting the columns and the column properties, one of which is the column's "Calculated Expression" property

  for tb in Document.Data.Tables:
    for col in tb.Columns:
      # initialize column variable
      ces = ""
      # get calculated expression and cast to string
      try:
        ces = col.Properties.CalculatedExpression.ToString()
      exception:
        ces="Error:Calculated Expression Not Read"

I know in advance that some of Calculated Expressions have unicode characters in them (can't do anything about that) so, I'm trying to "catch" those issues and simply write out the error.
Then go to the next column.
But, I continue to get the following error complaining about the greater than or equal to symbol:

System.Text.EncoderFallbackException: 'ascii' codec can't encode character '\u2264' in position 174

Was it helpful?

Solution

Doesn't explain it but what if you try:

for tb in Document.Data.Tables:
for col in tb.Columns:
  # initialize column variable
  ces = ""
  # get calculated expression and cast to string
  try:
    ces = str(col.Properties.CalculatedExpression)
  exception:
    ces="Error:Calculated Expression Not Read"

instead?

If that doesn't work look into the unicode() function.

str() docs - https://ironpython-test.readthedocs.org/en/latest/library/functions.html#str

unicode() docs - https://ironpython-test.readthedocs.org/en/latest/library/functions.html#unicode

I'd test it myself if there was example data given.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top