【发布时间】:2015-05-16 23:44:01
【问题描述】:
我想执行一个 python 类的函数。 Oauth.py
import....
class Oauth:
def __init__(self, requesttokenurl, accesstokenurl, resourceurl, version):
.....
def getList(self):
.......
return list
if __name__ == "__main__":
.......
我正在终端测试运行命令,我尝试运行以下命令。 命令:
python -c 'import Oauth; Oauth.getList()'
错误:
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'getList'
命令:
python -c 'from Oauth import *; print getList()'
错误:
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'getList' is not defined
命令:
python -c 'from Oauth import getList; print getList()'
错误:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: cannot import name getList
【问题讨论】: