0

I have many variables which has unicode values in python file as below :

var1 = u'urname'
var2 = u'myname'
var3 = u'name'

I can convert from unicode to string all the variables as:

var1 = str(var1)
var2 = str(var2)
var3 = str(var3)

But I want to know can we convert all the variables from unicode to string at single instance?

  • Why do you have so many separate variables in the first place? Why not use a list or a dictionary? That would make encoding all those strings to bytes much easier. – Martijn Pieters Feb 10 '16 at 09:57
  • Also, why do you need to convert to byte strings? If you are using `str()`, then the Unicode strings only contain ASCII codepoints so you can safely use these unicode strings everywhere a string is expected and Python auto-encodes for you anyway. – Martijn Pieters Feb 10 '16 at 09:58
  • All the variables are not related to each other , just as pseudo I havv given here. – user3516540 Feb 10 '16 at 09:58
  • Then encode each of those as needed. – Martijn Pieters Feb 10 '16 at 10:00

0 Answers0