You can convert every character of string
public class StringUnicode {
public static void main(String[] args) {
String foreignText = "برنامه نویسی";
String unicodevalue="";
for (int i = 0; i < foreignText.length(); i++) {
unicodevalue= unicodevalue+"\\u" + Integer.toHexString(foreignText.charAt(i) | 0x10000).substring(1);
}
System.out.println( unicodevalue );
// System.out.println(response);
}
}
output:
\u0628\u0631\u0646\u0627\u0645\u0647\u0020\u0646\u0648\u06cc\u0633\u06cc
in Python
Python 3 renamed the unicode type to str, the old str type has been replaced by bytes.
if isinstance(unicode_or_str, str):
text = unicode_or_str
decoded = False
else:
text = unicode_or_str.decode(encoding)
decoded = True
You may want to read the Python 3 porting HOWTO for more such details. There is also Lennart Regebro's Porting to Python 3: An in-depth guide, free online.
Last but not least, you could just try to use the 2to3 tool to see how that translates the code for you.
NameError: global name 'unicode' is not defined - in Python 3