我在Python 2.7
中观察到了str
对象的center
方法的奇怪行为 -
>>> print '-'.center(5,'.') # '-' is the minus or hyphen key on the keyboard.
..-.. # correctly centered
>>> print '─'.center(5, '.') # '─' is NOT the minus or hyphen key on the keyboard.
.─. # incorrectly centered
这是center
方法实现的一个错误还是与使用Unicode字符有关?
我该如何解决这个问题?
[请注意,在Python 3.2
中,这个方法可以完美地工作]
u"─"
有效。谢谢。但我想知道这种奇怪行为的原因。请把原因作为答案,我会给你点赞。 - Pushpak Dagade