Skip to content

Instantly share code, notes, and snippets.

@polymorphm
Last active August 29, 2015 13:57
Show Gist options
  • Save polymorphm/9891626 to your computer and use it in GitHub Desktop.
Save polymorphm/9891626 to your computer and use it in GitHub Desktop.
assert str is not bytes
def js_unicode_escape(unicode_str):
assert isinstance(unicode_str, str)
return ''.join(('\\u{:04x}'.format(ord(char)) for char in unicode_str))
print(js_unicode_escape('фигня'))
#!/usr/bin/bash
python3 -c'import sys; print("".join(("\\u{:04x}".format(ord(char)) for char in sys.argv[1])))' 'фигня'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment