草庐IT

some_flag

全部标签

python - 当我调用 `super(some_cls)` 时会发生什么魔法吗?

调查时thisquestion,我遇到了单参数super的这种奇怪行为:调用super(some_class).__init__()在some_class(或其子类)的方法内部工作,但在任何地方调用时都会抛出异常否则。代码示例:classA():def__init__(self):super(A).__init__()#doesn'tthrowexceptiona=A()super(A).__init__()#throwsexception抛出的异常是Traceback(mostrecentcalllast):File"untitled.py",line8,insuper(A).__i

python - Python 中的 Tarfile : Can I untar more efficiently by extracting only some of the data?

我正在从USGS订购一大堆陆地卫星场景,这些场景作为tar.gz存档。我正在编写一个简单的python脚本来解压缩它们。每个文件包含15张大小为60-120MB的tiff图像,总计刚刚超过2GB。我可以使用以下代码轻松提取整个文件:importtarfilefileName="LT50250232011160-SC20140922132408.tar.gz"tfile=tarfile.open(fileName,'r:gz')tfile.extractall("newfolder/")我实际上只需要这15个tiff中的6个,在标题中标识为“带”。这些是一些较大的文件,因此它们加在一起约

python - 'autodoc_default_flags' 在 python Sphinx 配置中如何工作?

我正在尝试使用Sphinx1.4和sphinx-apidoc以及sphinx.ext.autodoc扩展为我的python类生成文档。我有很多模块,我希望每个模块只显示类名,而不是类中方法的完整列表(我的代码中都有文档字符串)。这是我的conf.py文件的片段:sys.path.insert(0,'/blah/sphinx/src')extensions=['sphinx.ext.autodoc']autodoc_member_order='bysource'autodoc_default_flags=['no-members']这是一个玩具模块(my_module.py),我用它来了

python - 在 Python 中,some_string.lower() 和 str.lower(some_string) 有什么区别

我对Python中的内置方法感到困惑。例如,什么是some_string.lower()和str.lower(some_string)它们有何不同? 最佳答案 str是Python中所有字符串的类名。str.lower是它的方法之一。如果您在其中一个实例上调用lower(例如'ABC'.lower()),您将调用一个绑定(bind)方法,它自动将调用的对象作为第一个参数发送(通常称为self)。如果您在类本身上调用lower(即您使用str.lower()),那么您调用了一个未绑定(bind)方法,它不会自动提供self参数。因此,

python - some_string 中的 empty_string - 总是正确的?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Whyemptystringisoneverystring?我想知道为什么每当我检查空字符串是否在字符串中时Python都会返回True,以及为什么它的索引为零。例如:''in''=>true''.index('')=>0''in'notEmpty'=>true'notEmpty'.index('')=>0我在编写ROT13函数时注意到它,并对其进行测试我发现当我在空字符串上调用它时,它返回'n'('n'是字母表中的index13)。

python - tf.app.flags 是做什么的?为什么我们需要那个?

这个问题在这里已经有了答案:What'sthepurposeoftf.app.flagsinTensorFlow?(5个答案)关闭6年前。我正在阅读包含以下代码的tensorflow教程文件fully_connected_feed.py。我不明白那些是什么意思。为什么我们需要那个?看起来它只是定义了一些全局变量。为什么不直接定义它们呢?任何帮助表示赞赏。谢谢flags=tf.app.flagsFLAGS=flags.FLAGSflags.DEFINE_float('learning_rate',0.01,'Initiallearningrate.')flags.DEFINE_integ

python - 无法导入名称 _args_from_interpreter_flags

当我尝试在OSX10.6.8上的Python2.7.5中importmultiprocessing时,出现此错误:Traceback(mostrecentcalllast):File"",line1,inFile"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/__init__.py",line65,infrommultiprocessing.utilimportSUBDEBUG,SUBWARNINGFile"/Library/Frameworks/Python.framew

Python xml 迷你。生成 <text>Some text</text> 元素

我有以下代码。fromxml.dom.minidomimportDocumentdoc=Document()root=doc.createElement('root')doc.appendChild(root)main=doc.createElement('Text')root.appendChild(main)text=doc.createTextNode('Sometexthere')main.appendChild(text)printdoc.toprettyxml(indent='\t')结果是:Sometexthere这一切都很好,但如果我希望输出看起来像这样呢?Somete

python argparse : arg with no flag

我有以下代码:parser.add_argument('file',help='filetotest')parser.add_argument('-revs',help='rangeofversions',nargs='+',default=False)有没有办法在使用时不使用标志-revs,就像这样:./somescript.pysettings.json1234 最佳答案 是的。您有多种解决方案:正如Mrav提到的,您可以使用系统参数(sys.argv[0...])或者使用argparse。来自documentation(符合p

javascript - JavaScript 的 Array.prototype.some/every 的 python 等价物是什么?

python是否有与JavaScript的Array.prototype.some等价的东西?/every?简单的JavaScript示例:vararr=["a","b","c"];arr.some(function(element,index){console.log("index:"+index+",element:"+element)if(element==="b"){returntrue;}});将输出:index:0,element:aindex:1,element:b下面的python似乎在功能上是等价的,但我不知道是否有更“pythonic”的方法。arr=["a","b