草庐IT

check_raise

全部标签

python - asyncio 的 call_later raises 'generator' object is not callable with coroutine object

我有一些使用call_later使用Python3.4的asyncio制作的简单代码。代码应该打印,等待10秒,然后再次打印(但是在应该执行end()时引发TypeError,见下文):importasyncio@asyncio.coroutinedefbegin():print("Startingtowait.")asyncio.get_event_loop().call_later(10,end())@asyncio.coroutinedefend():print("completed")if__name__=="__main__":try:loop=asyncio.get_eve

python - 函数失败 : Raise Exception, 或返回 FALSE?什么是更好的方法?

我想知道你们是如何处理函数失败的。您是引发异常还是返回错误消息?例如我有一个应该连接到外部com对象的函数。如果com-object尚未通过另一个程序启动,则无法建立连接。通知主程序的首选python方式是什么?我应该使用详细的错误消息引发异常,还是应该简单地返回错误消息?谢谢! 最佳答案 python绝对是站在异常这一边的。我总能找到thisarticle成为一个很好的解释。 关于python-函数失败:RaiseException,或返回FALSE?什么是更好的方法?,我们在Stac

python - 请求——总是调用 raise_for_status

我想删除重复的x.raise_for_status()行:x=requests.get(url1)x.raise_for_status()y=requests.delete(url2)y.raise_for_status()z=requests.post(url3,data={'foo':'bar'})z.raise_for_status()如何自动调用raise_for_status()? 最佳答案 使用钩子(Hook)创建session:session=requests.Session()session.hooks={'resp

python - Pandas :带有 np.seterr(所有 ='raise')和缺失数据的 FloatingPointError

当我想查看涉及缺失数据的数据时,我收到了FloatingPointError。importnumpyasnpimportpandasaspdnp.seterr(all='raise')s=pd.Series([np.nan,np.nan,np.nan],index=[1,2,3]);print(s);print(s.head())我正在使用最新版本的pandas,通过安装condainstall-fpandas在pkillpython和condaremovepandas之后。这是回溯:Out[4]:--------------------------------------------

python - 在 Python 中 : check if file modification time is older than a specific datetime

我用C#编写了这段代码来检查文件是否已过期:DateTime?lastTimeModified=file.getLastTimeModified();if(!lastTimeModified.HasValue){//Filedoesnotexist,soitisoutofdatereturntrue;}if(lastTimeModified.Value我如何用python编写这个?我在python中试过了。statbuf=os.stat(filename)if(statbuf.st_mtime我得到以下异常messagestr:unsupportedoperandtype(s)for-

python - 为什么 Pylint 在此 raise 语句中给出错误 E0702,引发 NoneType?

假设我有以下代码。deffoo():foobar=NoneiffoobarisnotNone:raisefoobar当我通过pylint运行此代码时,出现以下错误:E0702:4:foo:RaisingNoneTypewhileonlyclasses,instancesorstringareallowed这是pylint中的错误吗?我的pylint太旧了吗?pylint0.18.0,astng0.19.1,common0.45.0Python2.5.1(r251:54863,Aug252008,09:23:26)注意:我知道这段代码没有任何意义,它被提炼到最基本的部分以暴露手头的问题,

没有参数的 Python 'raise' : what is "the last exception that was active in the current scope"?

Python的文档说:Ifnoexpressionsarepresent,raisere-raisesthelastexceptionthatwasactiveinthecurrentscope.(Python3:https://docs.python.org/3/reference/simple_stmts.html#raise;Python2.7:https://docs.python.org/2.7/reference/simple_stmts.html#raise。)但是,“最后激活”的概念似乎已经改变。见证以下代码示例:#from__future__importprint_f

python - 加密 : AssertionError ("PID check failed. RNG must be re-initialized after fork(). Hint: Try Random.atfork()")

我正在创建执行不同任务的各种流程。其中之一,也是唯一一个,有一个创建PyCrypto对象的安全模块。所以我的程序启动,创建各种进程,处理消息的进程使用安全模块解密,我得到以下错误:firstSymKeybin=self.cipher.decrypt(encFirstSymKeybin,'')File"/usr/local/lib/python2.7/dist-packages/Crypto/Cipher/PKCS1_v1_5.py",line206,indecryptm=self._key.decrypt(ct)File"/usr/local/lib/python2.7/dist-pa

python - `python setup.py check` 实际上是做什么的?

pythonsetup.pycheck到底做了什么? 最佳答案 第一站,distutilspackagedocumentation:Thecheckcommandperformssometestsonthemeta-dataofapackage.Forexample,itverifiesthatallrequiredmeta-dataareprovidedastheargumentspassedtothesetup()function.因此它会测试您是否正确填写了元数据;在创建Python包时将其视为质量控制步骤。接下来,我们可以检

python - pytest capsys : checking output AND getting it reported?

Python3.4.1,pytest2.6.2。当测试失败时,pytest将定期报告测试打印到标准输出的内容。例如这段代码:defmethod_under_test():print("Hallo,Welt!")return41deftest_result_only():result=method_under_test()assertresult==42当作为python-mpytestmyfile.py执行时,将报告:==================================FAILURES===================================________