Python文檔從http://docs.python.org/library/string.html:Python的錯誤, 「 '模塊' 對象沒有屬性 'lstrip'」
string.lstrip(s[, chars])
返回移除前導字符串的副本。如果省略字符或
None
,則刪除空白字符。如果給定而不是None
,字符必須是字符串;該字符串中的字符將調用此方法對字符串的開頭被剝離。」
Python 3.1.2 (r312:79360M, Mar 24 2010, 01:33:18)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> import string
>>> x = 'Hi'
>>> string.lstrip(x,1)
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
string.lstrip(x,1)
AttributeError: 'module' object has no attribute 'lstrip'
>>>
缺少什麼我在這裏?
它應該給你TypeError,因爲1不是char。 – Rozuur 2011-01-14 11:14:35