开发者

Python - Unicode to something split-able [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow开发者_开发知识库 situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

I need to break a date value down to it's elements ( 8/23/2011 ) which should be a piece of cake with

 variable.split("/") 

but it tells me that

'unicode' object has no attribute 'Split'

I tried encoding it as a different format:

date.encode("utf-8")

then it tells me that

'str' object has no attribute 'Split'

As A newbie to Python it seems like I've used split with strings before, but am not getting it to the right format or something. Or perhaps there is another way that is even easier.


Python is case-sensitive; you want split, not Split.

>>> x = u"8/23/2011"
>>> x.Split('/')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'unicode' object has no attribute 'Split'
>>> x.split('/')
[u'8', u'23', u'2011']


Python is case-sensitive. The method is called split, not Split.


unicode.split starts with a lower-case s and works fine:

>>> u'a,b'.split(u',')
[u'a', u'b']
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜