Strange character inserted with degrees character

I have a pretty simple function to get an engineering unit based on a description,

def getEngUnits(desc):
		eu = desc
		if "temp" in desc or "heat" in desc or "cool" in desc:
			eu = "°C"
		elif "pressure" in desc:
			eu = "kPa"
		return eu 

Then these go into a dataset, and instead of “°C” its showing “°C”. Anyone know why this is being inserted? I’ve tried with single quotes around it in the assignment, but no luck.

That suggests that some part of your setup isn’t handling encoding like the other parts. I make an effort to use UTF-8 everywhere to make sure this doesn’t happen.

° is outside of 8-bit ASCII, so you need to tell Python this is Unicode by doing this:
eu = u"°C"

1 Like

Great, thanks guys! Just tried that and it works great.

1 Like