今天写了个程序但是在DOS窗口和IDEL窗口调试的结果不一样,有些郁闷~

#!/usr/bin/env python  
#coding=utf-8  
#python version:2.7.3
#system:windows 7
#http://www.cnblogs.com/evilxr/
evilxr=raw_input("Evilxr:")
screen_width=80
text_width=len(evilxr)
box_width=text_width+2
left_margin=(screen_width - box_width) // 2
print
print ' ' *left_margin + '+' + '-' * (box_width-2) + '+'
print ' ' *left_margin + '|' + ' ' *  text_width   + '|'
print ' ' *left_margin + '|' +        evilxr       + '|'
print ' ' *left_margin + '|' + ' ' *  text_width   + '|'
print ' ' *left_margin + '+' + '-' * (box_width-2) + '+'
print

  

            

补充:

修改后代码如下,感谢Fooying的帮助:

#!/usr/bin/env python  
#coding=utf-8  
#python version:2.7.3
#system:windows 7
#http://www.cnblogs.com/evilxr/
evilxr=raw_input("Evilxr:")
try:
    evilxr = evilxr.decode('utf-8').encode('gbk')
except UnicodeDecodeError:
    pass
screen_width=80
box_width=text_width+2
left_margin=(screen_width - box_width) // 2
print
print ' ' *left_margin + '+' + '-' * (box_width-2) + '+'
print ' ' *left_margin + '|' + ' ' *  text_width   + '|'
print ' ' *left_margin + '|' +        evilxr       + '|'
print ' ' *left_margin + '|' + ' ' *  text_width   + '|'
print ' ' *left_margin + '+' + '-' * (box_width-2) + '+'
print

Fooying推荐pep8规范:http://baid.ws/cCBn