草庐IT

module_exit

全部标签

python - 在 pyqt 中将 sys.exit() 与 app.exec_ 一起使用

谁能解释一下使用sys.exit(app.exec_())而不是更简单的app.exec_()在PyQt中启动GUI的相对优点?我是PyQt的新手并且已经看过这两个示例。 最佳答案 当Unix风格的应用程序退出时,theyreturnanumbertotheirparentprocess称为“状态代码”或“退出状态”。0用于表示成功;任何非零值都是失败的。(有一些尝试standardisethemeaningoferrorcodes,但它通常仍然留给每个程序。)app.exec_()runsyourmainloop,andretur

python - 如何使用 "with"调用 tempfile.mkstemp() ? - 或者为什么它不返回带有 __exit__() 的 fd?

对我来说,调用tempfile.mkstemp()最惯用的方式是:withtempfile.mkstemp()asfd,filename:pass然而,这显然(?)引发了AttributeError:__exit__明确地使用try-finally调用os.close(fd)是解决此问题的一种简单方法,但感觉违反了应该有一个——最好只有一个——显而易见的方法。有没有一种方法可以在tempfile中“修复”这个问题,或者有什么理由可以这样实现吗? 最佳答案 with语句的工作原理在PEP343中定义。,包括其所谓的上下文管理协议(pr

python - 用于 Python 的 OpenCV - AttributeError : 'module' object has no attribute 'connectedComponents'

我正在使用以下OpenCV教程尝试分水岭算法:https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_imgproc/py_watershed/py_watershed.html#watershed我已经修复了一个错误,现在代码如下所示:importnumpyasnpimportcv2frommatplotlibimportpyplotaspltfromsysimportargvimg=cv2.imread(argv[1])gray=cv2.cvtColor(img,cv2.COLOR_BGR2G

python - 使用 os.scandir() 引发 AttributeError : __exit__

当我使用来自python文档(here)的示例代码时,引发了AttributeError。示例代码如下:withos.scandir(path)asit:forentryinit:ifnotentry.name.startswith('.')andentry.is_file():print(entry.name)结果是一个AttributeError:D:\Programming>test.pyTraceback(mostrecentcalllast):File"D:\Programming\test.py",line3,inwithos.scandir()asit:Attribute

Python pocketsphinx RequestError : missing PocketSphinx module: ensure that PocketSphinx is set up correctly

我正在尝试制作一个Python应用程序,它可以使用PyAudio、SpeechRecognition和PocketSphinx录制音频并将其翻译成英文文本。我在MacOSXElCapitan版本10.11.2上运行。遵循类似thisone的教程和其他人,我已经下载了PyAudio版本0.2.9、SpeechRecognition以及PocketSphinx。我已经将它们安装到Conda环境中。我已按照此site中的说明进行操作在我的OSX上使用brewinstallswiggitpython,希望它能有所帮助。这是我的代码:#Loadpackagesimportspeech_recog

python - 错误 : each element of 'ext_modules' option must be an Extension instance or 2-tuple

我试图在python中使用setuptools创建一个egg包,但我得到了这个奇怪的错误:error:eachelementof'ext_modules'optionmustbeanExtensioninstanceor2-tuple我该如何解决这个问题? 最佳答案 我不得不重新排序导入语句以消除此错误。此代码生成错误:fromCython.Buildimportcythonizefromsetuptoolsimportfind_packages,setup此代码不会产生错误:fromsetuptoolsimportfind_pac

python - AttributeError : module object has no attribute "Series". 代码在 iPython 中有效

子模块不是隐式导入的,必须显式声明,但我正在显式调用pd.Series子模块,不是吗?无论如何,importpandasaspd难道不应该允许调用pd.Series吗?以下代码在iPython中完美运行,但在从脚本执行时失败。#!/usr/bin/env/python2.7#-*-coding:utf-8-*-importpandasaspdimportnumpyasnpcounts=pd.Series([632,1638,569,115],index=["Firmicutes","Proteobacteria","Actinobacteria","Bacteroidetes"])结果

python - 无法使用 pip : error: command 'cc' failed with exit status 1 安装折扣

尝试在osx10.9Mavericks上安装discount包时,我遇到了很多问题。我正在使用django框架。我的步骤是(激活virtualenv时):pipinstalldiscount然后我得到:...1errorgenerated.error:command'cc'failedwithexitstatus1----------------------------------------Cleaningup...Command/Users/KaeserMic/Sites/2013/Duotones/naturkostbar/env/bin/python-c"importsetup

python - 导入错误 : No module named backend_tkagg

我有这样的导入和代码:importpandasaspdimportnumpyasnpimportstatsmodels.formula.apiassmimportmatplotlib.pyplotasplt#ReadthedatafrompydatasetsrepousingPandasurl='./file.csv'white_side=pd.read_csv(url)#Fittingthemodelmodel=sm.ols(formula='budget~article_size',data=white_side,subset=white_side['producer']=="Pe

python - 如何解决 ImportError : No module named 'dbus' ?

我在我的ubuntu上安装了anaconda4,我的Python上有这些模块:dbus-python(1.2.4)gi(1.2)pydbus(0.2)QtAwesome(0.3.2)qtconsole(4.2.0)QtPy(1.0)sip(4.18)我尝试安装dbus-python(1.2.4)和pydbus(0.2),但是,它们都不起作用!在python3.5.1中测试一个简单的程序后,出现错误:importdbussystem_bus=dbus.SystemBus()ImportError:Nomodulenamed'dbus'当我在Python2.7.11和3.5.1中使用pyd