我想创建新模型,例如:
user_name = models.ForeignKey(u"Username", User),
Run Code Online (Sandbox Code Playgroud)
但是当我尝试syncdb时,我收到以下错误消息:
"AttributeError:'unicode'对象没有属性'_meta'"
当我查看一些教程时,一切似乎与我的模型中的相同,并且从未提及"_meta"的问题.
我正在尝试编译glib-2.32.1,因此我安装libffi-3.0.1到以下路径:
~/localroot/lib/
Run Code Online (Sandbox Code Playgroud)
并且头文件位于:
~/localroot/lib/libffi-3.0.11/include/
Run Code Online (Sandbox Code Playgroud)
但是,当我配置时:
~/tmp/build_alot/glib-2.32.1 $ ./configure --prefix=~/localroot
Run Code Online (Sandbox Code Playgroud)
我看到以下错误:
checking whether to cache iconv descriptors... no
checking for ZLIB... yes
checking for LIBFFI... no
configure: error: Package requirements (libffi >= 3.0.0) were not met:
No package 'libffi' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables LIBFFI_CFLAGS
and LIBFFI_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for …Run Code Online (Sandbox Code Playgroud) 我试图比较re.match和re.search使用timeit模块,我发现当我想要找到的字符串位于字符串的开头时,匹配比搜索更好.
>>> s1 = '''
... import re
... re.search(r'hello','helloab'*100000)
... '''
>>> timeit.timeit(stmt=s1,number=10000)
32.12064480781555
>>> s = '''
... import re
... re.match(r'hello','helloab'*100000)
... '''
>>> timeit.timeit(stmt=s,number=10000)
30.9136700630188
Run Code Online (Sandbox Code Playgroud)
现在,我知道匹配在字符串的开头查找模式并返回一个对象(如果找到),但我想知道搜索是如何操作的.
在开头找到字符串后,搜索是否会执行任何额外的匹配,从而减慢它的速度?
更新
在使用@David Robinsons代码后,我得到了他的结果.
>>> print timeit.timeit(stmt="r.match('hello')",
... setup="import re; s = 'helloab'*100000; r = re.compile('hello')",
... number = 10000000)
49.9567620754
>>> print timeit.timeit(stmt="r.search('hello')",
... setup="import re; s = 'helloab'*100000; r = re.compile('hello')",
... number = 10000000)
35.6694438457
Run Code Online (Sandbox Code Playgroud)
那么,更新后的问题现在为什么search表现不佳match?
我有这个脚本
#!/bin/sh
if [ $# -ne 3 ] ; then
echo "param 1, param2, and A or B "
exit 1;
elif [ $# -eq 3 ]; then
if [$3 = "A"] ; then
echo "A"
elif [$3 = "B"]; then
echo "B"
fi
fi
Run Code Online (Sandbox Code Playgroud)
它基本上检查参数3是A还是B,然后做回声.但它返回:
./test.sh: line 6: [A: command not found
./test.sh: line 8: [A: command not found
Run Code Online (Sandbox Code Playgroud)
我试图-eq用于比较,但它仍然无效.我该如何解决这个问题?
让我说我创造了一个名为venv(virtualenv venv)的virtualenv
从阅读教程,我读到有两种方法来激活虚拟环境:
. venv/bin/activate
source venv/bin/activate
我认为他们都完成了同样的事情,但我不明白发生了什么.
对于数字1,不是"." 只是意味着当前的文件夹?但如果我只输入"venv/bin/activate"而没有".",它就无法工作.
任何帮助都会很棒!
如何使用shell脚本从特定字符串中删除所有n个字符,
ssl01:49188,,,
ssl01:49188,
ssl01:49188,,,,,
ssl01:49188,ssl999999:49188,,,,,
ssl01:49188,abcf999:49188,,,,,
Run Code Online (Sandbox Code Playgroud)
输出将采用以下格式
ssl01:49188
ssl01:49188
ssl01:49188
ssl01:49188,ssl999999:49188
ssl01:49188,abcf999:49188
Run Code Online (Sandbox Code Playgroud) 我有一个关于jQuery按键事件的问题.我有以下(工作)代码:
$(document).bind('keypress', function(event) {
if ($('#myDiv').is(':visible')) {
if (event.which == 102) {
// ...do something...
}
}
else {
if (event.which == 102) {
return;
}
}
});
Run Code Online (Sandbox Code Playgroud)
我总是"绑定"事件,绑定另一个"结束"它.我知道我可以解开它,.unbind('keypress')但是我得到了更多的按键事件,当我解开这个时,我的$(document).unbind('keypress')所有事件都会丢失.
我可以做一些像"keypress.102"这样的东西来解开这个特定的"密钥",或者怎么办呢?!
在预提交脚本中,是否有可能(如果是,如何)识别源自svn merge?的提交?
svnlook changed ... 显示已更改的文件,但不区分合并和手动编辑.
理想情况下,我还想区分标准merge和merge --reintegrate.
我正在探索使用预提交挂钩来为我们的项目强制执行SVN使用策略的可能性.
其中一个策略声明某些目录(例如/trunk)不应直接修改,只能通过功能分支的重新集成进行更改.因此,预提交脚本将拒绝除分支重新集成之外对这些目录所做的所有更改.
有任何想法吗?
我已经探索过这个svnlook命令,而我最接近的就是检测并解析svn:mergeinfo对目录属性的更改.这种方法有一些缺点:
svnlook可以标记属性的更改,但不会更改哪个属性.(需要使用proplist前一版本的差异)svn:mergeinfo,可以检测svn merge已运行的更改.但是,无法确定提交是否纯粹是合并的结果.合并后手动进行的更改将不会被检测到.(相关帖子:针对另一个路径/修订版的Diff事务树)函数begin_transaction接受一个布尔参数,指示应该进行什么类型的同步; 物理时为真或逻辑时为假.
当它指的是"物理"或硬同步时,它意味着什么?
我想知道如何在django中复制它:
for photo in gallery
if counter is 1
then use this photo
endif
endfor
Run Code Online (Sandbox Code Playgroud)
如果它是"1",我怎么检查forloop计数器?