python AttributeError何解?

以下代码运行出错,什么原因呢?


class Test:
    def prt(self):
        print(self)
        print(self.__class__)

t = Test()
t.prt()

AttributeError: 'Test' object has no attribute '_class_'

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Python AttributeError异常
遇到一个很奇怪的问题,本人刚学习Python ,在学类与对象的方法时,在调用方法时,我的对象名取名为k ,然而死活就是报AttributeError异常; 在反复检查代码无误后,然后我试着改一下名字,奇迹出现了,名字一改就好了,我以为不能使用单个字母,抱着试一试的心态,我将对象名改为a ,奇迹再次出现,成功了!!!规则不是很懂,还请大神指教nn```n class Person:n population=0n def __init__(self,name):n self.name=namen print '(Initializing %s)'%self.namen Person.population+=1n def __del__(self):n print'%s says bye.'%self.namen Person.population-=1n if Person.population==0:n print 'I am the last one.'n else:n print 'There are still %d people left.'% Person.populationn def sayHi(self):n print 'Hi,my name is %s.' % self.namen def howMany(self):n if Person.population==1:n print 'I am the only person here.'n else :n print 'We have %d persons here.' % Person.populationnswaroop=Person('swaroop')nswaroop.sayHi()nswaroop.howMany()nn# 此处有问题 na=Person('Abdul Kalam')na.sayHi()na.howMany()nnswaroop.sayHi()nswaroop.howMany()n```nn
AttributeError
Traceback (most recent call last):rn File "model_test.py", line 20, in rn import commonrn File "/home/tl/deeplab/common.py", line 45, in rn flags.DEFINE_enum('model_variant', 'xception_65', ['xception_65'],rnAttributeError: module 'tensorflow.python.platform.flags' has no attribute 'DEFINE_enum'rnrncommom.py,line45:rnflags.DEFINE_enum('model_variant', 'xception_65', ['xception_65'],rn 'DeepLab model variants.')rnrn
python:AttributeError:类没有属性‘***’
初学python遇到了问题rn按书上的代码敲的结果有BUGrnrn显示这个[color=#FF0000]File "D:/PycharmProjects/chapter9/electric_car.py", line 52, in rn my_tesla.battery.describe_battery()rnAttributeError: 'ElectricCar' object has no attribute 'battery'[/color]rnrnclass Car():rnrn def __init__(self, make, model, year):rn self.make = makern self.model = modelrn self.year = yearrn self.odometer_reading = 0rnrn def get_descriptive_name(self):rn long_name = str(self.year) + ' ' + self.make + ' ' + self.modelrn return long_name.title()rnrn def read_odometer(self):rn print("This car has " + str(self.odometer_reading) + " miles on it.")rnrn def update_odometer(self, mileage):rn if mileage >= self.odometer_reading:rn self.odometer_reading = mileagern else:rn print("You can't roll backk an odometer!")rnrn def increment_odometer(self, miles):rn self.odometer_reading += milesrnrnrnclass Battery():rn """一次模拟电动汽车电瓶的简单尝试"""rnrn def _init_(self, battery_size=70):rn """初始化电瓶属性"""rn self.battery_size = battery_sizernrn def describe_battery(self):rn """打印一条描述电瓶容量的消息"""rn print("This car has a " + str(self.battery_size) + "-kWh battery.")rnrnrnclass ElectricCar(Car):rn """电动汽车的独特之处"""rnrn def _init_(self, make, model, year):rn """rn 电动汽车的独特之处rn 初始化父类的属性,再初始化电动汽车持有的属性rn """rn super()._init_(make, model, year)rn self.battery = Battery()rnrnrnmy_tesla = ElectricCar('tesla', 'model s', 2016)rnprint(my_tesla.get_descriptive_name())rnmy_tesla.battery.describe_battery()rn
Python出现属性错误(Attributeerror)的原因之一
检查类中构造函数__init__()是否写正确,左右两边各两条下划线
python AttributeError: _exit_ 这是什么错误
python AttributeError: _exit_ 这是什么错误
Python中的AttributeError错误的常见原因
常见的原因如下: 类构造函数出了问题,本来是init()函数,但有几个类的构造函数成了_init,少了一个’_’符号 缩进不正确,把空格当做tab。
何解?
rn同一段代码如果放在。aspx里面不行,而放在cs里面就可以呢
何解
1。VC运行库中有没有那个函数能将一个整型数组中的相同数删除的,如有的话是什么?rnrn2。以下这段程序有错吗?rnrnstruct nstrn int x;rn int y;rn struct *next;rn;rnrnvoid aa(void)rnrn struct nst *nstart = new nst;rn bb(nstart);rnrnrnvoid bb(struct nst *ntmp)rnrn ntmp->next = new nst;rn rnrn
何解?何解?百思不得其解?
rn2000系统很慢,拔号软件(enternet300)拔N次打不开,出现:程序没有响应:rn而且kv2003的文件不完整了,在windows下删都删不掉,DOS下,scanreg /fix ,scanreg /restore也不能用了,用杀毒盘杀能杀也两三个来,杀了之后还是老样子,兔子也装上去用过了,我的电脑属性窗口打不开一点反应都没有,c:\winnt\下的temp被共享共享名为"game"rn怎么回事,如何解决?rn(通过服务器中转)
python报错:AttributeError: module 'curses' has no attribute 'wrapper'
windows平台 rnpython3.7.0rn在vscode下运行程序时rn其中curses.wrapper(main)报错rnrnrn```rnPS E:\dai ma\aaa> C:/Users/夏洛洛/AppData/Local/Programs/Python/Python37/python.exe "e:/dai ma/aaa/项目/2048.py"rnTraceback (most recent call last):rn File "e:/dai ma/aaa/项目/2048.py", line 219, in rn curses.wrapper(main)rnAttributeError: module 'curses' has no attribute 'wrapper'rnrn```rnrn 查询了下这个错误,可能是文件名并没有发生冲突,但换文件名后并没有排除。难道是windows平台问题吗?rn 求解,感激不尽。
python安装theano出现AttributeError错误解决办法
一、版本:theano为1.03,numpy为1.16.0,python版本为3.6 二、问题描述:AttributeError: ('The following error happened while compiling the node', Elemwise{Composite{((i0 * i1) + i2)}}(weight, input, bias), '\n', "module '...
Python中PyMySQL提示AttributeError: module 'socket' has no attribute 'AF_UNIX'
代码如下:rnfrom urllib.request import urlopenrnfrom bs4 import BeautifulSouprnimport rernimport datetimernimport randomrnimport pymysqlrnrnconn = pymysql.connect(host='127.0.0.1', unix_socket='/tmp/mysql.sock',rn user='root', passwd=None, db='mysql', charset='utf8')rncur = conn.cursor()rncur.execute("USE scraping")rnrnrandom.seed(datetime.datetime.now())rnrndef store(title, content):rn cur.execute("INSERT INTO pages (title, content) VALUES (\"%s\",\rn \"%s\")", (title, content))rn cur.connection.commit()rn rndef getLinks(articleUrl):rn html = urlopen("http://en.wikipedia.org"+articleUrl)rn bsObj = BeautifulSoup(html)rn title = bsObj.find("h1").get_text()rn content = bsObj.find("div", "id":"mw-content-text").find("p").get_text()rn store(title, content)rn return bsObj.find("div", "id":"bodyContent").findAll("a",rn href=re.compile("^(/wiki/)((?!:).)*$"))rnlinks = getLinks("/wiki/Kevin_Bacon")rntry:rn while len(links) > 0:rn newArticle = links[random.randint(0, len(links)-1)].attrs["href"]rn print(newArticle)rn links = getLinks(newArticle)rnfinally:rn cur.close()rn conn.close()rnrn编译后提示错误:rnTraceback (most recent call last):rn File "F:\爬虫\17-9-11.py", line 9, in rn user='root', passwd=None, db='mysql', charset='utf8')rn File "F:\Python 3.6\lib\site-packages\pymysql\__init__.py", line 90, in Connectrn return Connection(*args, **kwargs)rn File "F:\Python 3.6\lib\site-packages\pymysql\connections.py", line 706, in __init__rn self.connect()rn File "F:\Python 3.6\lib\site-packages\pymysql\connections.py", line 903, in connectrn sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)rn[color=#FF0000]AttributeError: module 'socket' has no attribute 'AF_UNIX'[/color]
用python scapy库分析pcap数据包错误TypeError、AttributeError
写了个python程序解析流量数据包,用的是scapy库。读取流量较少的pcap包文件时可以顺利运行,读取大点的pcap包就会报错。rn错误信息如下:rnrnrn```rn Traceback (most recent call last):rn File "C:\Users\ASUS\AppData\Local\Programs\Python\Python36\lib\site-packages\scapy\packet.py", line 235, in __getattr__rn fld, v = self.getfield_and_val(attr)rn TypeError: 'NoneType' object is not iterablernrn During handling of the above exception, another exception occurred:rnrn Traceback (most recent call last):rn File "C:\Users\ASUS\AppData\Local\Programs\Python\Python36\lib\site-packages\scapy\packet.py", line 235, in __getattr__rn fld, v = self.getfield_and_val(attr)rn TypeError: 'NoneType' object is not iterablernrn During handling of the above exception, another exception occurred:rnrn Traceback (most recent call last):rn File "D:\Paper\sta\pcap\特征提取.py", line 22, in rn bufLen.append(data.len)rn File "C:\Users\ASUS\AppData\Local\Programs\Python\Python36\lib\site-packages\scapy\packet.py", line 237, in __getattr__rn return self.payload.__getattr__(attr)rn File "C:\Users\ASUS\AppData\Local\Programs\Python\Python36\lib\site-packages\scapy\packet.py", line 237, in __getattr__rn return self.payload.__getattr__(attr)rn File "C:\Users\ASUS\AppData\Local\Programs\Python\Python36\lib\site-packages\scapy\packet.py", line 235, in __getattr__rn fld, v = self.getfield_and_val(attr)rn File "C:\Users\ASUS\AppData\Local\Programs\Python\Python36\lib\site-packages\scapy\packet.py", line 1291, in getfield_and_valrn raise AttributeError(attr)rn AttributeError: lenrn```rnrn源代码部分:rnrnrn```rn from scapy.all import *rn from scapy.utils import PcapReaderrnrn rd = PcapReader('./a.pcap') rn while True:rn data = rd.read_packet()rn if data is None:rn breakrn else:rn '''rn 分析处理过程rnrn '''rn rd.close()rn```rn源代码处理过程应该没问题,毕竟可以运行处理小数据包,但数据量一大就会报错。rn而且有时候不稳定,简单的同样的代码有时可以运行成功,有时也会报上面的错,我想是不是系统的问题,我用的是在windows10,内存16G应该足够大,为什么会报错呢,求大神解答!
python运行出错AttributeError: neuralnetwork instance has no attribute 'predict'
有两个py文件。rn一个是NeuralNetwork.py,代码如下:rnimport numpy as nprnrnrndef tanh(x):rn return np.tanh(x)rnrnrndef tanh_deriv(x):rn return 1.0 - np.tanh(x) * np.tanh(x)rnrnrndef logistic(x):rn return 1 / (1 + np.exp(-x))rnrnrndef logistic_derivative(x):rn return logistic(x) * (1 - logistic(x))rnrnrnclass neuralnetwork:rn def __init__(self, layers, activation='tanh'):rnrn if activation == 'logistic':rn self.activation = logisticrn self.activation_deriv = logistic_derivativern elif activation == 'tanh':rn self.activation = tanhrn self.activation_deriv = tanh_derivrnrn self.weights = []rn for i in range(1, len(layers) - 1):rn self.weights.append((2 * np.random.random((layers[i - 1] + 1, layers[i] + 1)) - 1) * 0.25)rn self.weights.append((2 * np.random.random((layers[i] + 1, layers[i + 1])) - 1) * 0.25)rnrn def fit(self, X, y, learning_rate=0.2, epochs=10000):rn X = np.atleast_2d(X)rn temp = np.ones([X.shape[0], X.shape[1] + 1])rn temp[:, 0:-1] = Xrn X = temprn y = np.array(y)rnrn for k in range(epochs):rn i = np.random.randint(X.shape[0])rn a = [X[i]]rnrn for l in range(len(self.weights)):rn a.append(self.activation(np.dot(a[l], self.weights[l])))rn error = y[i] - a[-1]rn deltas = [error * self.activation_deriv(a[-1])]rnrn for l in range(len(a) - 2, 0, -1):rn deltas.append(deltas[-1].dot(self.weights[l].T) * self.activation_deriv(a[l]))rn deltas.reverse()rn for i in range(len(self.weights)):rn layer = np.atleast_2d(a[i])rn delta = np.atleast_2d(deltas[i])rn self.weights[i] += learning_rate * layer.T.dot(delta)rnrn def predict(self, x):rn x = np.array(x)rn temp = np.ones(x.shape[0] + 1)rn temp[0:-1] = xrn a = temprn for l in range(0, len(self.weights)):rn a = self.activation(np.dot(a, self.weights[l]))rn return arnrn另一个是SimpleTest.py,代码如下:rnfrom NeuralNetwork import neuralnetworkrnimport numpy as nprnrnnn = neuralnetwork([2,2,1], 'tanh')rnX = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])rny = np.array([0, 1, 1, 0])rnnn.fit(X, y)rnfor i in [[0, 0], [0, 1], [1, 0], [1, 1]]:rn print (i, nn.predict(i))rnrn运行SimpleTest.py时出错,提示如下:rnD:\Users\dell\Anaconda2\python.exe D:/PyCharm/neuralNetwork/SimpleTest.pyrnTraceback (most recent call last):rn File "D:/PyCharm/neuralNetwork/SimpleTest.py", line 9, in rn print (i, nn.predict(i))rnAttributeError: neuralnetwork instance has no attribute 'predict'rnrnProcess finished with exit code 1
python "AttributeError: 'str' object has no attribute 'decode'"错误
代码如下:rn=================================代码==========================rnimport rernf1=open('J:/wenjian/1/1.txt','r').read()#把整个文件读进来作为整个字符串rnf1.decode()#把byte类型转换成string类型rnf1=re.sub('abcdef','123456',f1)#替换所有符合的情况rnprint (f1)#此时已经替换成功rnf_w=open('J:/wenjian/1/replace_1.txt','wb')#新建一个文件,把替换后的内容写进去rnf1=f1.encode('utf-8')#从string转换成bytes类型rnf_w.write(f1)#必须要是bytes类型才能写进去rnf_w.close()rn======================代码======================================rn报错如下:rnTraceback (most recent call last):rn File "J:\wenjian\python\test.py", line 8, in rn f1.decode()#把byte类型转换成string类型rnAttributeError: 'str' object has no attribute 'decode'rn>>> rnrn系统是win7*64 python 3.3.1版本。rn望大侠帮助。真诚感谢。
使用python预留字给模块命名AttributeError解决办法
报错:AttributeError: ‘module’ object has no attribute’xxx 解决办法:改变模块名称(不可使用python预留字、各类包名等),同时还要删除已经生成的pyc文件夹。 ...
python json报错:AttributeError: 'str' object has no attribute 'read'
#!/usr/bin/pythonrn#coding=gbkrnimport osrnimport json rnrnRes='["brief":"ooooo","class_extid":13,"create_time":你好,"face_id":4,"flag":6777217,"flag_ext":0,"level":0,"max_member":100,"memo":"m~F~M0m~Zm~@~B","name":"10502","option":2,"ul":["flag":4,"u":285,"flag":4,"u":35]]' rnrnqDic = json.load(Res)rnprint qDicrnfor i in qDic:rn print i["class_extid"]rn print i["flag"]rn for j in i["ul"]:rn print str(j["flag"]) + "===" + str(j["u"])rnrn执行后报错:rnTraceback (most recent call last):rn File "my.py", line 7, in rn qDic = json.load(Res)rn File "/usr/lib/python2.6/json/__init__.py", line 264, in loadrn return loads(fp.read(),rnAttributeError: 'str' object has no attribute 'read'rnrn请高手指点,万分感谢
python测试类报错:AttributeError: module '__main__' has no attribute 'test_name_functi
初学python,编写一个函数的单元测试,然后报错如下:rnEErn======================================================================rnERROR: test_name_function (unittest.loader._FailedTest)rn----------------------------------------------------------------------rnAttributeError: module '__main__' has no attribute 'test_name_function'rnrn======================================================================rnERROR: true (unittest.loader._FailedTest)rn----------------------------------------------------------------------rnAttributeError: module '__main__' has no attribute 'true'rnrn----------------------------------------------------------------------rnrnname_function.py:rn[code=python]def get_formatted_name(first,last,middle=''):rn if middle:rn full_name = first+" "+middle+" "+last;rn else:rn full_name = first+" "+last;rn return full_name.title();rn[/code]rnrntest_name_function.pyrn[code=python]import unittestrnfrom ch02.owntest.name_function import get_formatted_namernclass NameTestCase(unittest.TestCase):rn def test_first_last_name(self):rn format_name = get_formatted_name('king','ivan')rn self.assertEqual(format_name,'King Ivan')rnrnunittest.main()[/code]rnrn运行这个test_name_function中unittest.main()就报上面错误,有谁知道怎么回事么
AttributeError问题 求大佬解答
[img=https://img-bbs.csdn.net/upload/201801/09/1515429817_447527.png][/img]rnrn[code=python]from django.db import modelsrnrnclass Topic(models.Model):rn """用户学习的主题"""rn text = models.CharField(max_length=200)rn date_added = models.DataTimeField(auto_now_add=True)rnrn def _str_(self):rn '''返回模型的字符串表示'''rn return self.text[/code]rn rn脚本很简单 实在是不知道怎么出错了 就是运行不下去 求大佬解答啊
Hint 何解
我理解中Hint 为 可有可无,顾 忽略了。rn看到有代码,将edit.hint 作为if 判断条件.rnrn 求rn hint的意义,作用,用法
连接失败~!~何解?
[color=#FF0000]为什么会连接出问题[/color]?编译全ok~!rn//////////[color=#FF0000]mb.h[/color]///////rn#ifndef _mbrn#define _mbrn#includernusing namespace std;rntemplate rnclass Comparernpublic:rnCompare(T a,T b);rnT max();rnT min();rnprivate:rn T x,y;rnrnrn;rn#endifrn/////////////[color=#FF0000]hs.cpp[/color]/////////rn#include "mb.h"rntemplate rnCompare ::Compare(T a,T b)rnx=a;rny=b;rnrnrntemplate rnT Compare ::max()rnreturn (x>y)?x:y;rnrnrntemplate rnT Compare ::min()rnreturn (x c1(3.2,5.3);rncout<::max(void)" (?max@?$Compare@M@@QAEMXZ)rnmain.obj : error LNK2001: unresolved external symbol "public: float __thiscall Compare::min(void)" (?min@?$Compare@M@@QAEMXZ)rnmain.obj : error LNK2001: unresolved external symbol "public: __thiscall Compare::Compare(float,float)" (??0?$Compare@M@@QAE@MM@Z)rnDebug/第12题.exe : fatal error LNK1120: 3 unresolved externalsrnError executing link.exe.rnrn第12题.exe - 4 error(s), 0 warning(s)rnrn
此问题何解?
我用datagridrn其中有一列为操作项,当为管理者时此项可见。rnrn于是我在rnrn...rnrnrnrn可是我不知道如何让此列的visible为true。rnrn当为管理时,代码怎么写可以让TemplateColumn 此列的值为true
符号(void *)何解?符号(void **)又何解??
如题,谢谢!
_THROW 何解?
在看/usr/include/........中.h头文件对函数接口的定义时,总是能看到在函数结尾加一个_THROW,一时不明白这是什么意思,而且对于有些POSIX和ISO C不承认或未明确的定义的函数不加_THROW,注释中也会特别说明,该函数不会抛THROW,所以查了一下, 这是一个宏定义,是在GNU下的特色。在头文件#include 中定义: # if !defined __cplu
这句何解
当类实现特殊接口时,它定义(即将程序体给予)所有这种接口的方法。然后,它可以在实现了该接口的类的任何对象上调用接口的方法
int()何解?
int i = int();rn之后i = 0;rn标准里面何解?
此问题,何解???
一个关于ServerSocket与ClientSocket的问题,rnServerSocket要给ClientSocket通过SendText()发字符串,却出现Error:rnrnWindows Sock Error (10057): On API Sendrnrn谁给帮个忙,先谢了,当然还有分酬rn
何解?为什么?
rn与rn rn有何区别?rn为什么前者无错而后者有错?何解?有什么用?为什么?
正则表达式何解
alert("01".replace(/0*/g,"p"));rn alert("001".replace(/0*/g,"p"));rn alert("0101".replace(/0*/g,"p"));rnrnrn到底什么意思,怎么得到那样的结果
假死!!!!何解????????
我的机有时会假死机。一般是关闭窗口时就死了。不知为什么??用三热键结束任务rnrn也不行。等啊等啊,只好RESET。这样对硬盘会有损害吗?而且我的机好像不能用热rnrn键重启!??
Response.expires 何解?
请各位指点指点,小生看不懂这个属性要如何理解,能举个例子说明一下吗?谢谢!
这道何解
打印出以下杨辉三角形(要打出10行)rn1 1rn1 2 1rn1 3 3 1 rn1 4 6 4 1rn1 5 10 10 5 1 rn
算法何解!
各大哥:rn谁能给小弟一个计算不规则图形的面积大小!rn或是两个不规则图形的相交面积大小!rn有算法最好,方法也行!rn谢谢!rn
iis何解?
请教iis何解?
这个this何解?
创建对象时Animal a = new Aninmal(this);rnrnrn这个this是什么?
这一句何解?
CREATE TABLE [dbo].[borrowinfo] (rn [borrowno] [char] (14) COLLATE Chinese_PRC_CI_AS NOT NULL ,rn CREATE TABLE [dbo].[borrowinfo] (rn [borrowno] [char] (14) COLLATE Chinese_PRC_CI_AS NOT NULL ,rn [readerid] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ,rn [readername] [char] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,rn [bookid] [char] (14) COLLATE Chinese_PRC_CI_AS NOT NULL ,rn [bookname] [char] (40) COLLATE Chinese_PRC_CI_AS NOT NULL ,rn [borrowdate] [datetime] NULL ,rn [returndate] [datetime] NULL ,rn [memo] [text] COLLATE Chinese_PRC_CI_AS NULL rn) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]rn其中,collate Chinese_PRC_CI_AS 执行不通过,请问该句是什么意思,如何写能通过?rn
请问何解?
请问下列文件在JBuilder中为何编译为空白?(即Web View Source)rnrncarts.jsp文件:rnrnrnrnrnPlease enter item to add or remove :rnrn rn rn Add Item:rn rn rn NIN CDrn JSP安装rn Twin peaks tapesrn Switch bladern rn rn rn rn rn rn rn rn rnrn<%rn cart.processRequest(request);rn%>rnrn You have the following items in your cart:rn rn<%rn String[] items = cart.getItems();rn for (int i=0; irn <%= items[i] %>rn<%rn rn%>rnrnrn rnrn<%//@ include file="carts.html" %>rn
IIS何解!!!???
error CS0016: 未能写入输出文件“c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\webs\2c7c3781\3127e14c\m-cbfq96.dll”--“拒绝访问。rn请问各位大哥以上问题怎么解新决!??
AttributeError: 'Settings' object has no attribute 'DATABASE_ENGINE'
环境:Centos、python2.7.7 Django:1.7 south:0.7rnsettings.py 里的部分配置:rnINSTALLED_APPS = (rn 'south',rn 'django.contrib.admin',rn 'django.contrib.auth',rn 'django.contrib.contenttypes',rn 'django.contrib.sessions',rn 'django.contrib.messages',rn 'django.contrib.staticfiles',rn 'polls'rn)rn其中south:为同步模型到数据库的第三方模块,用来取代syncdb。rnpolls:为自己的投票应用。rn目前我执行python manage.py syncdb或者python manage.py startmigration polls --initial均报错,报错信息如下:rnTraceback (most recent call last):rn File "manage.py", line 10, in rn execute_from_command_line(sys.argv)rn File "/usr/local/python2.7/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/core/management/__init__.py", line 385, in execute_from_command_linern utility.execute()rn File "/usr/local/python2.7/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/core/management/__init__.py", line 377, in executern self.fetch_command(subcommand).run_from_argv(self.argv)rn File "/usr/local/python2.7/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/core/management/__init__.py", line 238, in fetch_commandrn klass = load_command_class(app_name, subcommand)rn File "/usr/local/python2.7/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/core/management/__init__.py", line 41, in load_command_classrn module = import_module('%s.management.commands.%s' % (app_name, name))rn File "/usr/local/python2.7/lib/python2.7/importlib/__init__.py", line 37, in import_modulern __import__(name)rn File "/usr/local/python2.7/lib/python2.7/site-packages/South-0.6-py2.7.egg/south/management/commands/syncdb.py", line 5, in rn from south import migrationrn File "/usr/local/python2.7/lib/python2.7/site-packages/South-0.6-py2.7.egg/south/migration.py", line 17, in rn from south.db import dbrn File "/usr/local/python2.7/lib/python2.7/site-packages/South-0.6-py2.7.egg/south/db/__init__.py", line 9, in rn module_name = '.'.join(['south.db', settings.DATABASE_ENGINE])rn File "/usr/local/python2.7/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/conf/__init__.py", line 47, in __getattr__rn return getattr(self._wrapped, name)rn[color=#FF0000]AttributeError: 'Settings' object has no attribute 'DATABASE_ENGINE'[/color]
错误:“AttributeError: module 'aiml' has no attribute 'Kernel'
初学Python 3.X,按照网页上的关于aiml的例子写了如下代码,运行总是报错:rnC:\Users\lenovo\PycharmProjects\aimltest\venv\Scripts\python.exe C:/Users/lenovo/PycharmProjects/aimltest/test1.pyrnTraceback (most recent call last):rn File "C:/Users/lenovo/PycharmProjects/aimltest/test1.py", line 17, in rn alice=aiml.Kernel()rnAttributeError: module 'aiml' has no attribute 'Kernel'rnC:\Users\lenovo\PycharmProjects\aimltest\venv\lib\site-packages\aiml\alicernrnProcess finished with exit code 1rn检查了目录,aiml下面也有Kernel.py,请问如何解决,谢谢大侠!rn-----------------------源代码------------------------------------rnrn# -*- coding: utf-8 -*-rnimport aimlrnimport sysrnimport osrnrndef get_module_dir (name):rnrn path = getattr(sys.modules[name], '__file__', None)rn if not path:rn raise AttributeError('模块 %s 没有 属性 __file__'%name)rn return os.path.dirname(os.path.abspath(path))rnrnalice_path =get_module_dir('aiml') +'\\alice'rnrnos.chdir(alice_path)rnprint(alice_path)rnalice=aiml.Kernel()rnalice.learn("std-startup.xml")rnalice.respond("load aiml b")rnrnwhile True:rn print(alice.respond(input("Enter your message >>")))rnrn
相关热词 c# stream 复制 android c# c#监测窗口句柄 c# md5 引用 c# 判断tabtip 自己写个浏览器程序c# c# 字符串变成整数数组 c#语言编程写出一个方法 c# 转盘抽奖 c#选中treeview