Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to print the value of an unicode string contained in a variable

I'm using python 2.7 and want to print the value of a field I receive on my server through a form.

I type André for the field name.

name = request.form['stripeBillingName']

How do I print the value of the variable name in a readable encoding? I want to print André and not Andr\xe9

like image 587
user7924113 Avatar asked Nov 22 '25 22:11

user7924113


1 Answers

In source header you can declare

#!/usr/bin/env python
# -*- coding: utf-8 -*-
....

After that you can use utf-8, which should give you your desirable format

name = request.form['stripeBillingName']
nameDec = name.decode('utf8')
print nameDec

You can also encode it however you want e.g:

nameEnc = nameDec.encode('cp1250')
like image 195
MirzaS Avatar answered Nov 26 '25 18:11

MirzaS