Parsing an arrow symbol into table header

I attempting to parse an arrow into the header of a power table. The console output shows the correct symbol but I get accented characters instead.

image

Here is a custom function that returns a symbol to be append to the custom header.

def goalSymbol(self, goal):
	"""
	Arguments:
		self: A reference to the component instance this method is invoked on. This argument
		  is automatic and should not be specified when invoking this method.
	"""

	up = u'\u2191' # up arrow
	down = u'\u2193' # down arrow
	print up
	print down
	
	if goal == "eq":
		return "="
	elif goal == "gt":
		return "{}".format(up)
	elif goal == "gte":
		return "{}=".format(up)
	elif goal == "lt":
		return "{}".format(down)
	elif goal == "lte":
		return "{}=".format(down)
	else:
		return "RA"

And here is some brief context of how that function is invoked, not shown is the append dataset functionality which does work. can show the entirety of the codeblock as well (part of the Initialize extension method) upon request.

	goal = kpi_collection['goal']
	target = "Target{}".format(self.goalSymbol(goal))
	headers = ["Unit",target,"Actual"]

Add u’ to the front of the symbol, but actually put the symbol in.

u'↑

a ‘u’ in front of “Target” should be enough.

Edit. Actually, that’s not quite right, You’ll need to specify unicode for everything if you keep it like this. The curly brace formatting does funky things when parsing.

	if goal == "eq":
		return "="
	elif goal == "gt":
		return u"{}".format(up)
	elif goal == "gte":
		return u"{}=".format(up)
	elif goal == "lt":
		return u"{}".format(down)
	elif goal == "lte":
		return u"{}=".format(down)
	else:
		return "RA"
target = u"Target{}".format(self.goalSymbol(goal))
1 Like

A more concise approach:

def goalSymbol(goal):
	up = u'\u2191' # up arrow
	down = u'\u2193' # down arrow

	symbolMap = {
		'eq': '=',
		'gt': up,
		'gte': up + '=',
		'lt': down,
		'lte': down + '='
	}

	return symbolMap.get(goal, "RA")	
2 Likes

@JordanCClark Thanks that worked!

@PGriffith Thank you, that does look a lot cleaner. I was going to use pattern matching but given this is Python 2.0 I assumed that wouldn’t work.