Python - Unicode可拆分的东西

Pau*_*ock -1 python unicode split

我需要将日期值分解为它的元素(8/23/2011),这应该是一块蛋糕

 variable.split("/") 
Run Code Online (Sandbox Code Playgroud)

但它告诉我

'unicode' object has no attribute 'Split'
Run Code Online (Sandbox Code Playgroud)

我尝试将其编码为不同的格式:

date.encode("utf-8")
Run Code Online (Sandbox Code Playgroud)

然后它告诉我

'str' object has no attribute 'Split'
Run Code Online (Sandbox Code Playgroud)

作为Python的新手,似乎我之前使用过split with strings,但我没有把它变成正确的格式或其他东西.或许还有另一种方式更容易.

Rus*_*ove 7

Python区分大小写; 你想要的split,不是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']
Run Code Online (Sandbox Code Playgroud)