0

I am translating a program from Java to Python.

In the source code of the Java program, the strings use the "\u000x" encoding for a few characters. As I understand, this is the unicode representation of the character and x is a hexadecimal code for that character.

In Java program the string is declared as:

data = "~\\GJ_F^A\u001eXJ]NK\u0018!"

How do I represent this in Python?

The above string has two encoded characters:

\u001e
\u0018

Thanks.

1

1 Answer 1

1

Python also has Unicode escape codes. This is valid python:

data = "~\\GJ_F^A\u001eXJ]NK\u0018!"
Sign up to request clarification or add additional context in comments.

2 Comments

Hello. Thanks for confirming. The issue in my case was that I was using Python 2.x version which did not have support for such encoding. I used Python 3.x and it worked properly.
good choice, not a good idea to do new projects in python2 - but you can use unicode escapes in unicode strings in python2 too docs.python.org/2/howto/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.