延迟绑定
Python闭包函数所引用的外部自由变量是延迟绑定的。
In [2]: def multipliers():
...: return [lambda x: i * x for i in range(4)]
In [3]: print [m(2) for m in multipliers()]
[6, 6, 6, 6]
如以上代码: i是闭包函数引用的外部作用域的自由变量, 只有在内部函数被调用的时候才会搜索变量i的值, 由于循环已结束, i指向最终值3, 所以各函数调用都得到了相同的结果。
解决方法:
1) 生成闭包函数的时候立即绑定(使用函数形参的默认值):
In [5]: def multip继续阅读 »
For those who don't know, Barbican is an OpenStack service which provides a REST API designed for the secure storage, provisioning and management of secrets such as passwords, encryption keys and X.509 certificates. Barbican can be used together with other OpenStack services to provide security features, e.g. Octavia u继续阅读 »
We recently added a new feature for xmake:
you need not write any make-like file (xmake.lua, makefile.am, cmakelist.txt, etc.) and also build it directly.
It will scan all source files and generate xmake.lua automatically for building project.
And xmake will detect 'main' function in source file in order to distin继续阅读 »
Oftentimes, we obtain a long or a wide table from a certain data source, and it may be the only format we can get. For example, some financial databases provide daily tick data for all stocks in a financial market. The data table may be arranged in a long format like this:继续阅读 »
android最近的support库提供了AlertDialog,可以让我们在低于5.0的系统使用到跟5.0系统一样的Material Design风格的对话框,但是使用了一段时间想到一些办法去改变对话框按钮字体的颜色,都不生效。
最近在网上找到了改变的方法,首先来说一下。
more
改变AlertDialog的样式
在xml中定义一个主题:
xml
<!-- Used for the buttons -->
<item name="colorAccent">#FFC107</item>
<!-- Used for the title and text -->
<item name="andr继续阅读 »
xmake在xmake.lua中提供了 $(varname) 的语法,来支持内置变量的获取,例如:
lua
add_cxflags("-I$(buildir)")
它将会在在实际编译的时候,将内置的 buildir 变量转换为实际的构建输出目录:-I./build
并且这些变量在自定义脚本中,也是可以支持的,例如:
lua
target("test")
after_build(target)
print("build ok for $(plat)!")
end
这将会在编译完后,输出:
lua
build ok for macosx!
这些内置变量,大部分都是通过配置的时候,缓存的继续阅读 »
Creature Mod Tutorial 1 - "Creating a Mod"
In this tutorial we're going to learn how to create our very own mod for 'Don't Starve'. Mods are a way for players to add their own content to the game. Creating a mod is really easy. All we need is two files and a folder and we're good to go. Let's get started!继续阅读 »