草庐IT

CURRENT_DIR

全部标签

python - Python 2 和 3 之间 "dir"的区别

以下代码在Python2和Python3中的行为不同,我不确定原因。classDataset(object):def__getattr__(self,item):ifnotitemindir(self):print(item)a=Dataset()a.HelloPython3中的结果:>HelloPython2中的结果:__members____members____methods__...无限循环,直到达到递归上限。“dir”的行为有何不同?编辑:有解决方法吗?self.dict是显而易见的选择,但它不包含在我的代码中证明是问题的函数。 最佳答案

python - 与 Python 的 dir() 等效的 Groovy 是什么?

在Python中,我可以看到对象具有哪些方法和字段:printdir(my_object)Groovy中的等价物是什么(假设它有一个)? 最佳答案 在Groovy中看起来特别好(未经测试,takenfromthislink所以代码来源应该放在那里)://Introspection,knowallthedetailsaboutclasses://ListallconstructorsofaclassString.constructors.each{printlnit}//Listallinterfacesimplementedbyac

python - 无法在 Windows 上导入 distutils.dir_util

我正在尝试在Windows764位上使用distutils.dir_util。据我从各种谷歌搜索中收集到的信息,我可能需要单独安装一些distutils包?我确实有可用的基本distutils包,但是它似乎被精简了很多并且缺少许多组件。尝试研究distutils和windows总是引导我使用python构建脚本以及如何将distutils打包为可再发行python项目的一部分或构建我不感兴趣的EXE,我根本看不到从哪里获得它的任何牵引力代码来自。已经很久了,但是我想我是从MSI安装程序安装Python的,不确定其他方法是否常见。这是我的解释器输出:Python2.7.3(default

没有参数的 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 - locals() 和 globals() 以及 python 中的 dir() 之间的区别

假设这段代码:>>>iterator=filter(lambdax:x%3==0,[2,18,9,22,17,24,8,12,27])>>>x=int()>>>locals(){'__package__':None,'__spec__':None,'__loader__':,'__name__':'__main__','__builtins__':,'iterator':,'x':0,'__doc__':None}>>>globals(){'__package__':None,'__spec__':None,'__loader__':,'__name__':'__main__','__

python - 导入错误 : No Module Named <parent dir>

我正在尝试通过Python学习编程,所以如果这是一个荒谬的简单问题,我提前道歉。我试图简化复杂的目录结构并利用Python的一些代码重用功能,我遇到了对我来说无法解释的ImportError错误。在过去的几个小时里,我一直在阅读有关Python的import、module和package功能(here、here、here和here其中其他),但我仍然无法解决这个(看似)简单的错误。问题来了。我有一个目录(dir),其中有一个子目录(subdir)。每个目录包含一些文件。因此,我的整体目录结构如下所示:dir/__init__.pydraw_lib.pysubdir/__init___.

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 - 为什么 cls.__name__ 没有出现在 dir() 中?

假设我有一个简单的类:classFoobar(object):pass如果我使用dir(Foobar),我将得到以下输出:['__class__','__delattr__','__dict__','__doc__','__format__','__getattribute__','__hash__','__init__','__module__','__new__','__reduce__','__reduce_ex__','__repr__','__setattr__','__sizeof__','__str__','__subclasshook__','__weakref__']

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