在这里,我们将给大家分享关于Ruby相当于Python的os.walk是什么?的知识,让您更了解ruby和python性能比较的本质,同时也会涉及到如何更有效地bash相当于Python的os.pat
在这里,我们将给大家分享关于Ruby相当于Python的os.walk是什么?的知识,让您更了解ruby和python性能比较的本质,同时也会涉及到如何更有效地bash相当于Python的os.path.normpath?、Groovy相当于Ruby的Object#tap、Javascript相当于python的.format()、os.path相当于python中的网址?的内容。
本文目录一览:- Ruby相当于Python的os.walk是什么?(ruby和python性能比较)
- bash相当于Python的os.path.normpath?
- Groovy相当于Ruby的Object#tap
- Javascript相当于python的.format()
- os.path相当于python中的网址?
Ruby相当于Python的os.walk是什么?(ruby和python性能比较)
有人知道Ruby内部是否有一个遍历文件系统目录和文件的模块/函数吗?我正在寻找类似于Python的东西os.walk
。我找到的最接近的模块是,Find
但需要一些额外的工作才能进行遍历。
Python代码如下所示:
for root,dirs,files in os.walk('.'):
for name in files:
print name
for name in dirs:
print name
bash相当于Python的os.path.normpath?
os.path.normpath
的bash?具体来说,我有兴趣删除执行find时给出的前导./.
matt@stanley:~/src/libtelnet-0.20/test$find . ./Makefile ./Makefile.in ./Makefile.am ...
解决方法
your_command_goes_here | sed 's?^\./??'
这将在一行开头摆脱所有./序列.
以下成绩单显示了这一点:
pax$find -name 'qq*sh' ./qq.ksh ./qq.sh ./qq.zsh ./qq2.sh ./qq2.zsh ./qqq/qq.sh pax$find -name 'qq*sh' | sed 's?^./??' qq.ksh qq.sh qq.zsh qq2.sh qq2.zsh qqq/qq.sh
正如您所看到的,我对我的临时shell脚本有一个相当直观的命名标准:-)
Groovy相当于Ruby的Object#tap
解决方法
Object.MetaClass.tap = { Closure c -> delegate.with c delegate } (1..10) .tap { println "original ${it}" } .findAll { it % 2 == 0 } .tap { println "evens ${it}" } .collect { it * it } .tap { println "squares ${it}" }
打印:
original [1,2,3,4,5,6,7,8,9,10] evens [2,10] squares [4,16,36,64,100]
Javascript相当于python的.format()
.format(*args,**kwargs)
前一个问题为’.format(* args)提供了一个可能的(但不是完整的)解决方案
JavaScript equivalent to printf/string.format
我希望能够做到
"hello {} and {}".format("you","bob" ==> hello you and bob "hello {0} and {1}".format("you","bob") ==> hello you and bob "hello {0} and {1} and {a}".format("you","bob",a="mary") ==> hello you and bob and mary "hello {0} and {1} and {a} and {2}".format("you","jill",a="mary") ==> hello you and bob and mary and jill
我意识到这是一个很高的订单,但也许某个地方有一个包含关键字参数的完整(或至少部分)解决方案.
哦,我听说AJAX和JQuery可能有这方面的方法,但我希望能够在没有这些开销的情况下完成它.
特别是,我希望能够将其与google doc的脚本一起使用.
谢谢
解决方法
如果没有,下面的代码适用于上面的所有情况,其语法与python的String.format方法非常相似.以下测试用例.
String.prototype.format = function() { var args = arguments; this.unkeyed_index = 0; return this.replace(/\{(\w*)\}/g,function(match,key) { if (key === '') { key = this.unkeyed_index; this.unkeyed_index++ } if (key == +key) { return args[key] !== 'undefined' ? args[key] : match; } else { for (var i = 0; i < args.length; i++) { if (typeof args[i] === 'object' && typeof args[i][key] !== 'undefined') { return args[i][key]; } } return match; } }.bind(this)); }; // Run some tests $('#tests') .append( "hello {} and {}<br />".format("you","bob") ) .append( "hello {0} and {1}<br />".format("you","bob") ) .append( "hello {0} and {1} and {a}<br />".format("you",{a:"mary"}) ) .append( "hello {0} and {1} and {a} and {2}<br />".format("you",{a:"mary"}) );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="tests"></div>
os.path相当于python中的网址?
解决方法
实际抓取网址和数据,你需要urllib2.
关于Ruby相当于Python的os.walk是什么?和ruby和python性能比较的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于bash相当于Python的os.path.normpath?、Groovy相当于Ruby的Object#tap、Javascript相当于python的.format()、os.path相当于python中的网址?等相关内容,可以在本站寻找。
本文标签: