草庐IT

attributeError

全部标签

Python-3.2 协程 : AttributeError: 'generator' object has no attribute 'next'

这个问题在这里已经有了答案:there'snonext()functioninayieldgeneratorinpython3(2个回答)关闭4个月前。引自PythonEssentialReference,DavidBeazley,第20页:Normally,functionsoperateonasinglesetofinputarguments.However,afunctioncanalsobewrittentooperateasataskthatprocessesasequenceofinputssenttoit.Thistypeoffunctionisknownasacorou

python - 使用 numpy.round 时出现 `AttributeError: rint`

我有一个如下所示的numpy数组:[[41.743617-87.626839][41.936943-87.669838][41.962665-87.65571899999999]]我想将数组中的数字四舍五入到小数点后两位或三位。我尝试使用numpy.around和numpy.round,但它们都给了我以下错误:File"/Library/Python/2.7/site-packages/numpy-1.8.0.dev_3084618_20130514-py2.7-macosx-10.8-intel.egg/numpy/core/fromnumeric.py",line2452,inro

python - 使用 numpy.round 时出现 `AttributeError: rint`

我有一个如下所示的numpy数组:[[41.743617-87.626839][41.936943-87.669838][41.962665-87.65571899999999]]我想将数组中的数字四舍五入到小数点后两位或三位。我尝试使用numpy.around和numpy.round,但它们都给了我以下错误:File"/Library/Python/2.7/site-packages/numpy-1.8.0.dev_3084618_20130514-py2.7-macosx-10.8-intel.egg/numpy/core/fromnumeric.py",line2452,inro

Python:AttributeError: '_io.TextIOWrapper' 对象没有属性 'split'

我有一个文本文件,我们称它为goodlines.txt,我想加载它并创建一个包含文本文件中每一行的列表。我尝试像这样使用split()过程:>>>f=open('goodlines.txt')>>>mylist=f.splitlines()Traceback(mostrecentcalllast):File"",line1,inAttributeError:'_io.TextIOWrapper'objecthasnoattribute'splitlines'>>>mylist=f.split()Traceback(mostrecentcalllast):File"",line1,inA

Python:AttributeError: '_io.TextIOWrapper' 对象没有属性 'split'

我有一个文本文件,我们称它为goodlines.txt,我想加载它并创建一个包含文本文件中每一行的列表。我尝试像这样使用split()过程:>>>f=open('goodlines.txt')>>>mylist=f.splitlines()Traceback(mostrecentcalllast):File"",line1,inAttributeError:'_io.TextIOWrapper'objecthasnoattribute'splitlines'>>>mylist=f.split()Traceback(mostrecentcalllast):File"",line1,inA

python - AttributeError:模块 Django.contrib.auth.views 没有属性

在我的Django应用用户帐户中,我为我的注册创建了一个注册表单和一个模型。但是,当我运行pythonmanage.pymakemigrations时,遇到错误:AttributeError:moduleDjango.contrib.auth.viewshasnoattribute'registration'。其次,我在forms.py中正确编码SignUpForm吗?我不想在模型中使用User模型,因为它会请求用户名,我不希望我的网站要求用户名。这是我的代码:models.pyfromdjango.dbimportmodelsfromdjango.db.models.signalsi

python - AttributeError:模块 Django.contrib.auth.views 没有属性

在我的Django应用用户帐户中,我为我的注册创建了一个注册表单和一个模型。但是,当我运行pythonmanage.pymakemigrations时,遇到错误:AttributeError:moduleDjango.contrib.auth.viewshasnoattribute'registration'。其次,我在forms.py中正确编码SignUpForm吗?我不想在模型中使用User模型,因为它会请求用户名,我不希望我的网站要求用户名。这是我的代码:models.pyfromdjango.dbimportmodelsfromdjango.db.models.signalsi

python - 运行 GAE 开发服务器时,本地 MySQLdb 连接失败并出现 AttributeError for paramstyle

我正在使用Flask-Alchemy针对CloudSQL构建一个GAEFlask应用程序,并在构建应用程序时运行dev_appserver来测试该应用程序。但是,如果我将SQLALCHEMY_DATABASE_URI设置为mysql+gaerdbms:///appname?instance=instanceidURL,我会在尝试调用db.create_all():Traceback(mostrecentcalllast):#earlierlinesomittedforbrevityFile"/Project/app/foo.bar/foo/bar/admin/__init__.py",

python - 运行 GAE 开发服务器时,本地 MySQLdb 连接失败并出现 AttributeError for paramstyle

我正在使用Flask-Alchemy针对CloudSQL构建一个GAEFlask应用程序,并在构建应用程序时运行dev_appserver来测试该应用程序。但是,如果我将SQLALCHEMY_DATABASE_URI设置为mysql+gaerdbms:///appname?instance=instanceidURL,我会在尝试调用db.create_all():Traceback(mostrecentcalllast):#earlierlinesomittedforbrevityFile"/Project/app/foo.bar/foo/bar/admin/__init__.py",

python - 访问实例属性时修补类会产生 "AttributeError: Mock object has no attribute"

问题将mock.patch与autospec=True一起使用来修补类不会保留该类实例的属性。详情我正在尝试测试一个类Bar,它将类Foo的实例实例化为名为foo的Bar对象属性.被测的Bar方法叫做bar;它调用属于Bar的Foo实例的方法foo。在测试这一点时,我正在模拟Foo,因为我只想测试Bar是否正在访问正确的Foo成员:importunittestfrommockimportpatchclassFoo(object):def__init__(self):self.foo='foo'classBar(object):def__init__(self):self.foo=Foo