草庐IT

attribute_exists

全部标签

python、__slots__ 和 "attribute is read-only"

我想在python中创建一个具有一些属性的对象,并且我想保护自己免于意外使用错误的属性名称。代码如下:classMyClass(object):m=None#myattribute__slots__=("m")#ensurethatobjecthasno_metca=MyClass()#createonea.m="?"#hereisaPROBLEM但是在运行这个简单的代码之后,我得到了一个非常奇怪的错误:Traceback(mostrecentcalllast):File"test.py",line8,ina.m="?"AttributeError:'test'objectattrib

python - TensorFlow AttributeError : 'NoneType' object has no attribute 'TF_DeleteStatus'

Tensorflow给了我这个Unresolved错误:Exceptionignoredin:>Traceback(mostrecentcalllast):File"/opt/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py",line532,in__del__AttributeError:'NoneType'objecthasnoattribute'TF_DeleteStatus'错误已讨论here.问题是它没有始终如一地出现。但是,它经常出现在我的终端中。有没有人设法绕过它。谢谢。

python - PyODBC : can't open the driver even if it exists

我是linux世界的新手,我想从Python查询MicrosoftSQLServer。我在Windows上用过,非常好,但在Linux上就很痛苦。几个小时后,我终于用unixODBC在LinuxMint上成功安装了MicrosoftODBC驱动程序。然后,我用python3环境设置了一个anaconda。然后我这样做:importpyodbcasodbcsql_PIM=odbc.connect("Driver={ODBCDriver13forSQLServer};Server=XXX;Database=YYY;Trusted_Connection=Yes")它返回:('01000',"

python - 属性错误 : 'module' object has no attribute 'model'

谁能帮我解决这个问题..fromdjango.dbimportmodels#Createyourmodelshere.classPoll(models.model):question=models.CharField(max_length=200)pub_date=models.DateTimeField('datepublished')classChoice(models.Model):poll=models.ForeignKey(Poll)choice=models.CharField(max_length=200)votes=models.IntegerField()运行:c:\

python - 单元测试 : Assert that a file/path exists

我正在尝试为我的安装程序创建回归测试。回归测试是用Python编写的脚本。测试检查是否已将正确的文件安装在正确的位置。有没有办法断言文件/文件夹存在?我收到以下代码的AssertionError错误:assertos.path.exists(LOCAL_INSTALL_DIR)==1为什么会出现此错误,我该如何解决?我的功能:defcheck_installation_files_exist():assertos.path.exists(LOCAL_INSTALL_DIR)==1assertos.path.exists(INSTALL_DIR)==1correct_install_fi

Python 与 Selenium : unable to locate element which really exist

我一直在尝试填充输入:为此,我必须找到这个元素。我尝试了以下方法:pass1=driver.find_element_by_name("PASSFIELD1")pass1=driver.find_element_by_id("PASSFIELD1")pass1=driver.find_element_by_xpath("/html/body/div[4]/div/div/div[2]/div/form/div[3]/table/tbody/tr[3]/td[2]/div/input[1]")(firebug的路径)甚至等待100秒self.wait.until(EC.visibilit

Python; urllib 错误 : AttributeError: 'bytes' object has no attribute 'read'

注意:这是Python3,没有urllib2。另外,我试过使用json.loads(),我得到这个错误:TypeError:can'tuseastringpatternonabytes-likeobject如果我使用json.loads()并从响应中删除.read(),我会收到此错误:TypeError:expectedstringorbuffer>importurllib.requestimportjsonresponse=urllib.request.urlopen('http://www.reddit.com/r/all/top/.json').read()jsonRespons

Python distutils 错误 : "[directory]... doesn' t exist or not a regular file"

让我们采用以下项目布局:$ls-R..:packagesetup.py./package:__init__.pydirfile.datmodule.py./package/dir:tool1.dattool2.datsetup.py的内容如下:$catsetup.pyfromdistutils.coreimportsetupsetup(name='pyproj',version='0.1',packages=['package',],package_data={'package':['*','dir/*',],},)如您所见,我想在package/和package/dir/目录中包含所

python - Django : Table doesn't exist

我删除了一些与应用相关的表格。并再次尝试了syncdb命令pythonmanage.pysyncdb它显示像这样的错误django.db.utils.ProgrammingError:(1146,"Table'someapp.feed'doesn'texist")模型.pyclassfeed(models.Model):user=models.ForeignKey(User,null=True,blank=True)feed_text=models.CharField(max_length=2000)date=models.CharField(max_length=30)upvote=

python - 将 "NoneType object has no attribute"用于自定义上下文管理器时获取 "with ... as"

我用Python编写了一个简单的上下文管理器来处理单元测试(并尝试学习上下文管理器):classTestContext(object):test_count=1def__init__(self):self.test_number=TestContext.test_countTestContext.test_count+=1def__enter__(self):passdef__exit__(self,exc_type,exc_value,exc_traceback):ifexc_value==None:print'Test%dpassed'%self.test_numberelse:p