cancel
Showing results for 
Search instead for 
Did you mean: 

Dev Space

Customize & extend the power of Alteryx. SDKs, APIs, custom tools, and more!

Python Tool to Translate Hexidecimal to Unicode

Highlighted
Alteryx
Alteryx

Hi Developers!

 

I saw this post in the Alteryx Designer Discussions, and although Alteryx does support Unicode encoding by default, it does not have a native way of translating other encodings into Unicode. This got me wondering if there might be a way to leverage the Python SDK for this task. I was able to modify the Python Single Input Output Example Tool to accomplish this task. The core of the code is a function that translates hexadecimal to Unicode.

 

def unicodeTrans(msg):
	new_msg = []
	for char in msg:
		try:
			char = chr(ord(char))
		except ValueError:
			char = '?'
		new_msg.append(char)
	return ''.join(new_msg)
			

 

This function was working really well when ran in an IDE, but was failing to execute the translation in the Python SDK Tool. It turned out this was because of the way values are passed through the Alteryx Engine to Python. The Python SDK uses UTF-8, and the input values are passed in from the engine as strings. This required that I convert the strings to bytes before passing them into the translation function, in order for the function to work properly. 

 

bts = bytes(text, 'utf-8').decode("unicode_escape")
result = unicodeTrans(bts)

 

This is a pretty simple tool, but I had a lot of fun with this exercise learning more about the Python SDK!

 

 

 

Alteryx
Alteryx

Really cool use case @SydneyF! Thanks so much for sharing