0

I have some code:

report['ipconfig'] = [line.decode('cp866') for line in report['ipconfig']]

Can I make this code more simple?

4

4 回答 4

0

I don't know if this is more simple (what does that even mean?), but it's a different way of doing it:

report['ipconfig'] = map(lambda x : x.decode('cp866'), report['ipconfig'])
于 2013-07-26T12:20:58.937 回答
0

Do you need something more verbose?

lst = list()
for line in report['ipconfig']:
    lst.append(line.decode('cp866'))
report['ipconfig'] = lst
于 2013-07-26T12:25:40.807 回答
0

You can use codecs module to read initial data. Wrap your reader in codecs.getreader and reencoding becomes not needed.

于 2013-07-26T12:25:40.783 回答
0

Seomthing like this ?

for i, line in enumerate(report['ipconfig']):
    report['ipconfig'][i] = line.decode('cp866') 
于 2013-07-26T12:26:00.427 回答