草庐IT

current_item

全部标签

python - tkinter TreeView : get selected item values

我刚开始使用python3.4中的一个小型tkinter树程序。我坚持返回所选行的第一个值。我有多行,有4列,我在左键单击一个项目时调用了一个函数:tree.bind('',selectItem)函数:defselectItem(a):curItem=tree.focus()print(curItem,a)这给了我这样的东西:I003看起来所选项目已被正确识别。我现在需要的是如何获取行中的第一个值。树的创建:fromtkinterimport*fromtkinterimportttkdefselectItem():passroot=Tk()tree=ttk.Treeview(root,

python - Mercurial 预提交 Hook : How to hook to python program in current directory?

我正在尝试创建一个MercurialHook,该Hook在提交被推送到主存储库时运行。我创建了一个python脚本,如下所示:#commit.pyfrommercurialimportui,hgfrommercurial.i18nimportgettextas_defgetV1ID(ui,repo,**kwargs):ui.write("Thehookworks!!!")v1id=ui.prompt('EntertheVersionOneID')ui.write('VersionOneID:'+v1id)对于每个分支,此commit.py都是重复的,因为它包含在代码被推送到主存储库之前

python - 如何创建自定义 Scrapy Item Exporter?

我正在尝试创建一个基于JsonLinesItemExporter的自定义ScrapyItemExporter,这样我就可以稍微改变它生成的结构。我已阅读此处的文档http://doc.scrapy.org/en/latest/topics/exporters.html但它没有说明如何创建自定义导出器、将其存储在何处或如何将其链接到您的管道。我已经确定了如何使用FeedExporter进行定制,但这不符合我的要求,因为我想从我的管道中调用这个导出器。这是我想出的代码,它存储在项目根目录中名为exporters.py的文件中fromscrapy.contrib.exporterimport

没有参数的 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 - Sublime Text : How to get the file name of the current view

我正在尝试编写一个小插件来删除当前文件并关闭事件View。出于某种原因,self.view.file_name()总是返回None。我是Python的新手,我不知道为什么它不能像这样工作。根据APIReferencefile_name()返回当前View的文件名。importsublime,sublime_plugin,send2trashclassDeleteCurrentFileCommand(sublime_plugin.TextCommand):defrun(self,edit):f=self.view.file_name()if(fisNone):returnsend2tra

python - Django 模板以 "items"为键遍历 dictionary.items

我的模板中有一个字典,我想以通常的方式循环访问它{%forkey,valueindictionary.items%}但在字典中我有一个名为'items'的键,所以我的循环返回字典['items']的值并尝试将结果解包为键,值。如何告诉Django使用函数items而不是访问key? 最佳答案 改为调用dictionary.iteritems?我认为没有更好的方法。如果您无法控制字典键,唯一安全的方法是使用自定义标签迭代字典。 关于python-Django模板以"items"为键遍历di

键的Python循环索引,使用items()时的值for-loop

我正在使用遍历字典forkey,valueinmydict.items():我想知道是否有一些pythonic方法也可以访问循环索引/迭代次数。访问索引,同时仍然保持对键值信息的访问。forkey,value,indexinmydict.items():这是因为我需要检测第一次循环运行的时间。所以在里面我可以有类似的东西ifindex!=1: 最佳答案 您可以使用enumerate函数,像这样forindex,(key,value)inenumerate(mydict.items()):printindex,key,valueenu

python - 如何为pytest设置current_user?

我正在为在查询中使用当前登录用户的View编写单元测试:@app.route('/vendors/create',methods=['GET','POST'])@login_requireddefcreate_vendors():vendor_form=VendorForm(request.form)ifvendor_form.validate_on_submit():vendor=db.session.query(Vendors).filter(Vendors.name==vendor_form.name.data,Vendors.users.contains(g.user)).fi

python - PyYAML : Control ordering of items called by yaml. 加载()

我有一个yaml设置文件,它在数据库中创建了一些记录:setting1:name:[item,item]name1:textanothersetting2:name:[item,item]sub_setting:name:[item,item]当我使用setting3更新此文件并通过以下方式在数据库中重新生成记录时:importyamlfh=open('setting.txt','r')setting_list=yaml.load(fh)foriinsetting_list:add_to_db[i]重要的是,每次将它们添加到数据库时,它们的设置顺序(数据库中的ID号)保持相同...并且

python - 不能在 jinja2 宏中使用 current_user?

我使用Flask-Login,它在模板中提供了current_user对象。我想编写一个宏来根据用户是否登录来显示评论表单或登录链接。如果我直接在模板中使用此代码,它会起作用:{%ifcurrent_user.is_authenticated%}{{quick_form(form)}}{%else%}LogInwithGithub{%endif%}我将相同的代码放在一个宏中,然后将宏导入到我的模板中。{%macrocomment_form(form)%}{%ifcurrent_user.is_authenticated%}...{%endif%}{%endmacro%}{%from"m