Novice Python (3.7) question here - I'm attempting to decode a Python dictionary's keys which are represented as lists of byte objects to a class but am seeing that the byte notation is not being removed as a part of decoding.
Can anyone help me achieve this without just bolting on something like v.replace("b", "")?
Application.py
from Person import Person
person = {
'firstName': [b'Foo'],
'lastName': [b'Bar'],
'email': [
b'foo.bar@example.com',
b'bar.foo@example.com',
],
}
p = Person(person)
print(p.firstName)
print(p.lastName)
print(p.email)
Person.py
class Person(object):
def __init__(self, dictionary):
for key in dictionary:
value_list = dictionary[key]
for v in value_list:
v.decode('utf-8')
setattr(self, key, dictionary[key])
Running Application.py outputs this
[b'Foo']
[b'Bar']
[b'foo.bar@example.com', b'bar.foo@example.com']
But I require this (without "b'" notation)
['Foo']
['Bar']
['foo.bar@example.com', 'bar.foo@example.com']