私はPython2.3.2を使用しています。スクリプトでは、デリメータに基づいて文字列を分割したいと思います。だから呼び出しrpartition()
ます。しかし、Pythonは次のエラーを示しています
AttributeError: 'str' object has no attribute 'rpartition'
しかし、Pythonインタープリターは実行しています:
>>> cmd
'CHG-CELL-PARAM:CELL_IDX=0fff,NYL=43;3'
>>> cmdStr=cmd.rpartition(";")
>>> cmdStr
('CHG-CELL-PARAM:CELL_IDX=0fff,NYL=43', ';', '3')
>>>
インタプリタにある間、'str'オブジェクトには次のものがあります。
>>> dir(str)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__',
'__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__',
'_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find',
'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip',
'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip',
'swapcase', 'title', 'translate', 'upper', 'zfill']
>>>
私のスクリプトの同じ出力は次のようになります。
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind', 'rindex', 'rjust', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
str関数はインタープリターに含まれていますが、私のスクリプトには含まれていません。インストールしているPythonは1つだけで、スクリプトとインタープリターの両方が同じpythonexeを使用しています。見逃したことはありますか?