假设我有一个功能
def oldfunction(arg1,arg2,arg3):
print(arg1,arg2,arg3)
Run Code Online (Sandbox Code Playgroud)
我想创建一个新函数,我将第一个参数设置为10.新的函数行为将是:
>>> new_function(20,"30")
10 20 '30'
Run Code Online (Sandbox Code Playgroud)
一种方法是使用lambda函数:
>>> newfunction = lambda arg2,arg3: function(10,arg2,arg3)
>>> newfunction("ten",[10])
(10, 'ten', [10])
Run Code Online (Sandbox Code Playgroud)
但是,假设我事先并不知道"旧功能"有多少参数.我仍然想创建一个与"oldfunction"相同的新函数,但是第一个参数设置,并且所有后续参数都保持打开状态.
有没有办法做到这一点?
用
<input type="text" onKeyPress="alert(this.value)">
Run Code Online (Sandbox Code Playgroud)
警报框将在框中显示值,不包括当前按下的键。
但是,这并不表现出相同的行为,我也不知道为什么。
<input type="text" onKeyPress="handleInput(this.value)">
function handleInput(value){
alert(value);
}
Run Code Online (Sandbox Code Playgroud)
rm -i *
如果我输入,我想要bash运行rm *
,否则运行常规rm
.重要的是,我不想rm -i
每次使用通配符时都运行rm part*
.据我所知,这是:
rm ()
{
if [ "$1" == "*" ]; then
rm -i *
else
rm $1
fi
}
Run Code Online (Sandbox Code Playgroud)
但我知道这会失败.我知道我想要的比较是^*$
,但我不知道如何实现它.
我尝试导入时遇到错误,dask.dot
无法找到graphviz安装.但是,安装了graphviz和pygraphviz.
balter@exalab3:~$ conda install dask
Fetching package metadata ...........
Solving package specifications: ..........
# All requested packages already installed.
# packages in environment at /home/.../miniconda3:
#
dask 0.13.0 py35_0 conda-forge
balter@exalab3:~$ python
Python 3.5.3 | packaged by conda-forge | (default, Jan 23 2017, 19:01:48)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dask.dot
Traceback (most recent call last):
File "/home/.../miniconda3/lib/python3.5/site-packages/dask/utils.py", line 63, in import_required
return import_module(mod_name)
File …
Run Code Online (Sandbox Code Playgroud) 这似乎是sed
捕获组中最简单的可能示例之一,但它不起作用.我已经在在线正则表达式测试中测试了正则表达式,并且做了我想要的.在linux命令行,它没有.
$ echo "a 10 b 12" | sed -E -n 's/a ([0-9]+)/\1/p'
$
Run Code Online (Sandbox Code Playgroud)
和
$ echo "a 10 b 12" | sed -E -n 's/a ([0-9]+)/\1/p'
10 b 12
Run Code Online (Sandbox Code Playgroud)
https://regex101.com/r/WS3lG9/1
我希望能抓住"10".
CFWheels有形式帮手,cfwheels.org 试图说服我们更好更容易使用.为了自我一致,我想使用它们.但我发现缺乏id
属性使他们难以定型.例如,因为表单助手不支持id
标签,我不能选择何时使它们可见,应用背景图像,或者基本上我想要做的任何事情CSS
.div
如果我愿意的话,控件助手可以让你在标签和控件前面添加标签和控件,但为什么这比仅仅围绕它们更容易div
- 如果我只是使用HTML
表单,这是不必要的.此外,这会导致不必要的混乱呈现的HTML.
一个简单的答案是"只使用最适合你的东西".但我想知道为什么我应该使用表单助手,以及如何处理所有样式限制?为什么heck不仅支持id标签,如"id"和"label-id"!
我只是学习jquery,而且我遇到了我不理解的行为.我有:
HTML:
<div id="tour" data-location="london">
<button>Get Photos</button>
<ul class="photos"></ul>
</div>
Run Code Online (Sandbox Code Playgroud)
和jquery:
var tour = {
init: function () {
$("#tour").on("click", "button", alert("clicked"));
}
};
$(document).ready(function () {
alert("hello");
tour.init();
});
Run Code Online (Sandbox Code Playgroud)
正如我所料,在加载dom之后出现"hello"警报.然而,"点击"警报也会被触发,并且在按下按钮时不会随后触发.
我有以下脚本:
a=$1
b=$2
if [ ! a ]; then
echo "a=$a"
elif [ b ]; then
echo "b=$b"
fi
Run Code Online (Sandbox Code Playgroud)
这是我可以称之为的四种可能方式:
balter$ bash eliftest.sh true true
b=true
balter$ bash eliftest.sh true false
b=false
balter$ bash eliftest.sh false true
b=true
balter$ bash eliftest.sh false false
b=false
Run Code Online (Sandbox Code Playgroud)
我原以为:
b=true # !a evaluates to false but b is true
<nothing> # !a evaluates to false and b is also false
a=false # !a evaluates to true and if short circuits
a=false # !a evaluates …
Run Code Online (Sandbox Code Playgroud) 这是一个带有匿名回调的简单的AJAX请求.双方complete
并error
已触发.为什么?
$.ajax({
url:'/echo/js/?js=hello%20world!',
complete: function (response) {
console.log("In anonymous success callback");
console.log("response text: " + response.responseText);
console.log("response object:");
console.log(response);
},
error: function (error) {
console.log("In anonymous error callback");
console.log("error object:");
console.log(error);
}
});
Run Code Online (Sandbox Code Playgroud)
https://jsfiddle.net/abalter/tz0tu04y/
编辑 我尝试使用promises,现在我只是得到错误.我的"简单的"ajax肯定有问题.
$.ajax({
url: '/echo/js/?js=hello%20world!',
type: 'POST',
})
.done(function(response) {
console.log("In anonymous JS success callback");
console.log("response text: " + response.responseText);
console.log("response object:");
console.log(response);
})
.fail(function(error) {
console.log("In anonymous JS error callback");
console.log("error object:");
console.log(error);
})
.always(function(data) {
console.log("JS I will always do …
Run Code Online (Sandbox Code Playgroud) bash ×3
javascript ×3
jquery ×2
python ×2
regex ×2
ajax ×1
anaconda ×1
arguments ×1
callback ×1
cfwheels ×1
coldfusion ×1
conda ×1
conditional ×1
dask ×1
form-helpers ×1
forms ×1
function ×1
graphviz ×1
html ×1
if-statement ×1
lambda ×1
onclick ×1
onkeypress ×1
regex-group ×1
rm ×1
sed ×1
shell ×1
wildcard ×1