草庐IT

gtk_init_check

全部标签

python - 当 grep 找不到匹配项时,使用 grep 命令的 subprocess.check_output 失败

我正在尝试搜索一个文本文件并检索包含一组特定单词的行。这是我正在使用的代码:tyrs=subprocess.check_output('grep"^A"%s|grepTYR'%pocket_location,shell=True).split('\n')当文件至少包含grep识别的一行时,这会很好地工作。但是当grep没有识别任何行时,grep返回退出状态1并且我收到以下错误:Traceback(mostrecentcalllast):File"../../Python_scripts/cbs_wrapper2.py",line324,intyrs=subprocess.check_o

python - 在 __init__ 中定义成员与在 python 的类主体中定义它之间的区别?

做和做有什么区别classa:def__init__(self):self.val=1做classa:val=1def__init__(self):pass 最佳答案 classa:def__init__(self):self.val=1这会创建一个类(在Py2中,一个粗糙的、遗留的、旧式的,不要那样做!类;在Py3中,讨厌的旧遗留类终于消失了,所以这会是一种且唯一的类——**好*类,它需要classa(object):inPy2)这样每个实例都以它自己对整数对象的引用开始1。classa:val=1def__init__(self

python - Selenium - visibility_of_element_located : __init__() takes exactly 2 arguments (3 given)

我在使用SeleniumPython绑定(bind)的测试代码中遇到此错误:>twitter_campaigns=wait.until(EC.visibility_of_element_located(By.CSS_SELECTOR,TWITTER_CAMPAIGNS))ETypeError:__init__()takesexactly2arguments(3given)这就是我正在执行的:classTestTwitter(TestLogin,TestBuying):defsetup(self,timeout=10):self.driver=webdriver.Firefox()sel

python - Python 中的 GTK3 对话框,Gtk.Entry 上的 "enter key"应该触发确定按钮

我使用Gtk3用Python编写了以下代码。fromgi.repositoryimportGtkclassDialogTaskDescription(Gtk.Dialog):def__init__(self):Gtk.Dialog.__init__(self,"CreateToDo.txtEntry",0,0,(Gtk.STOCK_CANCEL,Gtk.ResponseType.CANCEL,Gtk.STOCK_OK,Gtk.ResponseType.OK))self.set_default_size(150,100)hbox=Gtk.Box(orientation=Gtk.Orien

python - 编写 Python GTK+ 应用程序的 'good practice' 方法是什么?

我目前正在编写一个PyGTK应用程序,我需要一些关于构建我的应用程序的最佳方式的建议。基本上,应用程序将读取特定的文件规范并将其呈现在GUI中以供编辑。目前我有一个parser.py,它处理所有低级文件IO和文件解析。我在TreeView中显示文件的内容,这意味着我需要使用树存储作为我的数据类型。我遇到的问题是,我只想到了两个解决这个问题的方法。第一个是我的解析器可以构建一个树存储并将其传递给我的ui类。这需要我的解析器依赖于pygtk,并最大限度地减少类的潜在重用。第二个是在解析器中存储对我的ui类的引用,这也可能会限制我的解析器类作为独立库的重用。将我的问题浓缩成一个简短的一行:有

python - 如何忽略 ‘imported but unused’ 文件中的 Pyflakes 错误 ‘__init__.py’?

我将我的测试拆分到多个Python文件中:tests├──__init__.py├──test_apples.py└──test_bananas.py.py我在“__init__.py”文件中导入测试:fromtest_applesimportApplesTestfromtest_bananasimportBananasTest但是在命令行上运行Pyflakes:pyflakes.输出以下错误:tests/__init__.py:1:[E]PYFLAKES:'ApplesTest'importedbutunusedtests/__init__.py:2:[E]PYFLAKES:'Ban

python - 在 Nose 测试课上使用 __init__(self) 而不是 setup(self) 有缺点吗?

为运行nosetests-sclassTestTemp():def__init__(self):print'__init__'self.even=0defsetup(self):print'__setup__'self.odd=1deftest_even(self):print'test_even'even_number=10asserteven_number%2==self.evendeftest_odd(self):print'test_odd'odd_number=11assertodd_number%2==self.odd打印出以下内容。__init____init____se

Python __init__.py 与 sys.path.append/insert

我know那里are一个ton的how-to进口Pythonmodules不在路径中,但我还没有遇到过使用Python的__init.py__与sys.path.insert。哪种方法更好?是否有任何明显的缺点,比如性能?还有一个“Pythonic”吗?我能想到的一个场景是,我有一个用户下载并放在任何目录中的程序,所以我不知道绝对路径(除非我以编程方式获取它)。文件夹结构为workingdir__init__.pyfoo.pysrc/my_utils.py__init__.py我看不出使用__init__.py或更改sys.path有什么区别。您是否可以想到任何情况会有所作为?我的问题

python - 在 GTK3 中显示股票图标的非弃用方式是什么?

我正在使用PyGObject组装一个GUI。此Python代码在上下文中工作。我得到一个带有常用“打开”图标的工具栏按钮。fromgi.repositoryimportGtk#...toolbar=Gtk.Toolbar()toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)#...self.fileOpen=Gtk.ToolButton.new_from_stock(Gtk.STOCK_OPEN)self.fileOpen.connect("clicked",self.on_FileOpenSta

python - 为什么 `subprocess.check_call(..., stderr=sys.stdout)` 在 Python 2.6 中失败?

Python2.6.9(unknown,Mar72016,11:15:18)[GCC5.3.0]onlinux2Type"help","copyright","credits"or"license"formoreinformation.>>>importsys>>>importsubprocess>>>subprocess.check_call(['echo','hi'],stderr=sys.stdout)echo:writeerror:BadfiledescriptorTraceback(mostrecentcalllast):File"",line1,inFile"/usr/li