myPythonClient(下面)想要调用一个ringBell函数(使用DLL加载ctypes).但是,尝试ringBell通过其名称访问会导致AttributeError.为什么?
RingBell.h 包含
namespace MyNamespace
{
class MyClass
{
public:
static __declspec(dllexport) int ringBell ( void ) ;
} ;
}
Run Code Online (Sandbox Code Playgroud)
RingBell.cpp 包含
#include <iostream>
#include "RingBell.h"
namespace MyNamespace
{
int __cdecl MyClass::ringBell ( void )
{
std::cout << "\a" ;
return 0 ;
}
}
Run Code Online (Sandbox Code Playgroud)
myPythonClient.py 包含
from ctypes import *
cdll.RingBell[1]() # this invocation works fine
cdll.RingBell.ringBell() # however, this invocation errors out
# AttributeError: function 'ringBell' …Run Code Online (Sandbox Code Playgroud) 我正在附加特定路径c:\ important\log.txt中的文件
sender = 'poojagupta4112@gmail.com'
receiver = ['shubh4112@gmail.com']
message = """From: From Pooja Gupta <poojagupta4112@gmail.com>
To: To Shubha Goel <shubh4112@gmail.com>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
file_name = 'C:\important\log.txt'
msg=MIMEMultipart()
msg['From'] = sender
msg['To'] = receiver
msg['Subject'] = message
msg['Date'] = email.Utils.formatdate(localtime=True)
# build the attachment
att = MIMEBase('application', 'base64')
att.set_payload(open(file_name, 'rb').read())
email.Encoders.encode_base64(att)
att.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(file_name))
msg.attach(att)
print 'successfully built attachment'
try:
session = smtplib.SMTP('smtp.gmail.com',587)
print 'Starting..'
session.ehlo()
print 'ehlo executed..'
session.starttls()
print …Run Code Online (Sandbox Code Playgroud) 问题:我一直在使用Google的Python脚本示例将apk上传到Play商店并获取通过我的帐户发布的应用列表(list_apks.py和upload_apk.py).然而最近它开始打破.我试图通过这样做来更新类似的软件包google-api-python-client,但它没有帮助.oath2clientpip install --update packagename
日志:
这个如果在列出apk的时候:
Determining latest version for my.package.name...
error 25-Feb-2016 06:30:52 Traceback (most recent call last):
error 25-Feb-2016 06:30:52 File "list_apks.py", line 80, in <module>
error 25-Feb-2016 06:30:52 main()
error 25-Feb-2016 06:30:52 File "list_apks.py", line 46, in main
error 25-Feb-2016 06:30:52 credentials = client.SignedJwtAssertionCredentials(
error 25-Feb-2016 06:30:52 AttributeError: 'module' object has no attribute 'SignedJwtAssertionCredentials'
build 25-Feb-2016 06:30:52 Found latest APK version:
build 25-Feb-2016 06:30:52 Generated …Run Code Online (Sandbox Code Playgroud) python android attributeerror oauth2client google-play-developer-api
>import tensorflow
>import tensorflow.contrib
>tensorflow.contrib
module 'tensorflow.contrib' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\tensorflow\\contrib\\__init__.py'
>import tensorflow.python
>tensorflow.python
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'python'
Run Code Online (Sandbox Code Playgroud)
如您所见,我在cmd(win 10)中运行此代码."import tensorflow.contrib"和"import tensorflow.python"都可以,但命令"tensorflow.contrib"和"tensorflow.python"是不同的.一个返回一个目录,另一个返回AttributeError.
有没有人知道为什么?
python3 无法识别任何 tensorflow 属性
AttributeError: 模块“tensorflow”没有属性“variable_scope”
AttributeError: 模块“tensorflow”没有属性“squared_difference”
已安装张量流
pip3 列表 | grep tensorflow tensorflow 2.0.0
tensorflow-estimator 2.0.1
AttributeErrors我在@property与 python 结合使用时遇到了一个问题__getattr__():
示例代码:
>>> def deeply_nested_factory_fn():
... a = 2
... return a.invalid_attr
...
>>> class Test(object):
... def __getattr__(self, name):
... if name == 'abc':
... return 'abc'
... raise AttributeError("'Test' object has no attribute '%s'" % name)
... @property
... def my_prop(self):
... return deeply_nested_factory_fn()
...
>>> test = Test()
>>> test.my_prop
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 5, in __getattr__
AttributeError: 'Test' object …Run Code Online (Sandbox Code Playgroud) 我在数据帧dtype中有一个列'delta':timedelta64 [ns],通过从另一个日期转包一个日期来计算.我试图通过使用此代码返回浮动天数:
from datetime import datetime
from datetime import date
df['days'] = float(df['delta'].days)
Run Code Online (Sandbox Code Playgroud)
但是我收到这个错误:
AttributeError: 'Series' object has no attribute 'days'
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
我正在尝试掌握SciPy,但是Unknown property density即使我从SciPy官方文档中复制了整个代码,也仍然遇到错误。
这部分工作正常:
x = np.linspace(norm.ppf(0.01), norm.ppf(0.99), 100)
ax.plot(x, norm.pdf(x), 'r-', lw=5, alpha=0.6, label='norm pdf')
rv = norm()
ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')
r = norm.rvs(size=1000)
Run Code Online (Sandbox Code Playgroud)
但是以下部分给我AttributeError: Unknown property density:
ax.hist(r, density=True, histtype='stepfilled', alpha=0.2)
ax.legend(loc='best', frameon=False)
plt.show()
Run Code Online (Sandbox Code Playgroud) 当我运行我的代码时,我收到以下错误消息。
Traceback (most recent call last):
File "C:/Users/user/PycharmProjects/MyDevWork/PygamesRelated/game_1.py", line 29, in <module>
elif event.key == pygame.K_s:
AttributeError: 'Event' object has no attribute 'key'
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
import pygame
pygame.init()
screen = pygame.display.set_mode((720, 480))
clock = pygame.time.Clock()
FPS = 60
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
rect = pygame.Rect((0, 0), (32, 32))
image = pygame.Surface((32, 32))
image.fill(WHITE)
while True:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_w:
rect.move_ip(0, -2) …Run Code Online (Sandbox Code Playgroud) 如果您的问题作为此问题的重复项而被关闭,那是因为您有一些通用形式的代码
x = X()
# later...
x = x.y()
# or:
x.y().z()
Run Code Online (Sandbox Code Playgroud)
其中X是某种类型,它提供了y旨在z变异(修改)对象(X类型的实例)的方法。这可以适用于:
list、dict和setbytearray这种形式的代码很常见,但并不总是错误的。问题的明显迹象是:
与x.y().z()一样,会引发异常AttributeError: 'NoneType' object has no attribute 'z'。
有了x = x.y(),x就变成None, 而不是被修改的对象。这可能会被后来的错误结果发现,或者被像上面这样的异常(x.z()稍后尝试时)发现。
Stack Overflow 上有大量关于这个问题的现有问题,所有这些问题实际上都是同一个问题。之前甚至有多次尝试在特定上下文中涵盖同一问题的规范。然而,理解问题并不需要上下文,因此这里尝试一般性地回答:
代码有什么问题吗?为什么这些方法会这样,我们如何解决这个问题?
另请注意,当尝试使用 alambda(或列表理解)来产生副作用时,会出现类似的问题。
同样明显的问题可能是由因其他原因返回的方法引起的None …
attributeerror ×10
python ×8
android ×1
ctypes ×1
dll ×1
getattr ×1
matplotlib ×1
nonetype ×1
oauth2client ×1
properties ×1
pygame ×1
python-2.7 ×1
tensorflow ×1
timedelta ×1