我知道".pyc"文件是纯文本".py"文件的编译版本,在运行时创建以使程序运行得更快.但是我发现了一些事情:
rm *.pyc
)后,程序行为有时会发生变化.这表明他们没有在".py"更新时编译.问题:
在Fabric网站上,给出了这个例子:
from fabric.api import env
env.roledefs = {
'web': {
'hosts': ['www1', 'www2', 'www3'],
'foo': 'bar'
},
'dns': {
'hosts': ['ns1', 'ns2'],
'foo': 'baz'
}
}
Run Code Online (Sandbox Code Playgroud)
据我在文档中可以看出,在主机'www1','www2','www3'上执行时,此设置应该为env dict键'foo'赋值'bar'.虽然结构正确地确定了主机,但我无法获得此行为.一个示例fabfile:
env.foo = 'WRONG'
@task()
def set_role():
env.roles.append('web')
@task()
def print_foo():
print env.foo
Run Code Online (Sandbox Code Playgroud)
示例命令:
fab set_role print_foo
Run Code Online (Sandbox Code Playgroud)
意外的输出:
[www1] Executing task 'print_foo'
WRONG
[www2] Executing task 'print_foo'
WRONG
[www3] Executing task 'print_foo'
WRONG
Done.
Run Code Online (Sandbox Code Playgroud)
我误解了这个的目的吗?我怎样才能使一个服务器看到一个不同的密钥值而另一个服务器没有太多麻烦?
我正在使用fabric 1.10.0
我需要在 Linux 上的 python 代码中为文件提供属性(元数据),特别是 Ubuntu。
具体来说,我需要在 MP4 文件上设置作者、标题、专辑等。
我在Python3中使用Gstreamer在Gtk3中创建了一个视频播放器.除非我添加GtkMenuBar(位置2),否则它的工作原理.然后它将显示黑屏,或者因异常而失败.这个例外引用了XInitThreads
我正在调用的(Place 1)(我从pitivi项目中获取了这个),但这似乎并没有产生差异.
问题:我如何使这项工作?
我想知道的其他事情:
系统:
例外:
[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
python3: ../../src/xcb_io.c:179: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq' failed.
Run Code Online (Sandbox Code Playgroud)
代码(以尽可能小的形式展示概念):
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gst', '1.0')
gi.require_version('GstVideo', '1.0')
from gi.repository import Gtk, xlib
from gi.repository import Gst, Gdk, GdkX11, GstVideo
Gst.init(None)
Gst.init_check(None)
# Place 1
from ctypes import cdll
x11 = cdll.LoadLibrary('libX11.so')
x11.XInitThreads() …
Run Code Online (Sandbox Code Playgroud) 我有一些问题让这个工作:
# Shortened for brevity
def _coerce_truth(word):
TRUE_VALUES = ('true','1','yes')
FALSE_VALUES = ('false','0','no')
_word = word.lower().strip()
print "t" in _word
if _word in TRUE_VALUES:
return True
elif _word in FALSE_VALUES:
return False
Run Code Online (Sandbox Code Playgroud)
我发现:
In [20]: "foo" is "Foo".lower()
Out[20]: False
In [21]: "foo" is "foo".lower()
Out[21]: False
In [22]: "foo" is "foo"
Out[22]: True
In [23]: "foo" is "foo".lower()
Out[23]: False
Run Code Online (Sandbox Code Playgroud)
为什么是这样?我理解身份与平等不同,但身份何时形成?False
除非由于字符串的静态性质,否则声明22应该是id == eq.在这种情况下,我对陈述23感到困惑.
请提前解释并表示感谢.
通过优化模式,我的意思是没有断言,可能没有文档字符串,.pyo
而不是.pyc
.
简而言之,我有一个 django 项目,以标准样式 ( ) 通过 Gunicorn(v18.0)gunicorn 'module.wsgi:application'
运行
我无法在文档或在线其他地方找到参考。
我有一个django应用程序,删除数据库中的所有条目,然后进入另一个集合.我有一个问题,Model.objects.all().delete()
在数据库中留下对象(每次都是相同的条目).
我已使用此代码修复它:
db_events = Event.objects.all()
while db_events.count():
db_events.delete()
Run Code Online (Sandbox Code Playgroud)
显然,这不是一个很好的解决方案.发生了什么,我该如何解决?
我正在尝试在 d 中使用libgit2库。我总是在程序退出时遇到分段错误。当我打开和关闭存储库时,在退出之前不会发生错误。这似乎是垃圾收集器的问题,但手动禁用垃圾收集器(GC.disable();)似乎根本不会影响结果。释放(git_repository_free(repo))似乎也没有效果。
这是一些示例代码:
import std.stdio : writeln;
import std.string : toStringz;
import core.memory : GC;
import deimos.git2.types : git_repository;
import deimos.git2.repository : git_repository_open, git_repository_free;
void main() {
GC.disable();
git_repository *repo;
git_repository_open(&repo, ".".toStringz());
git_repository_free(repo);
writeln("END");
}
Run Code Online (Sandbox Code Playgroud)
输出:
$ ./gittest
END
zsh: segmentation fault (core dumped) ./gittest
Run Code Online (Sandbox Code Playgroud)
版本:
如果有的话,我做错了什么?如果没有什么可以确定错误的罪魁祸首(d、libgit2 或 libgit2 d 绑定)?
附加说明:我尝试使用 dlibgit 并发现它有令人难以置信的错误,主要是看起来已经过时了。这个问题涉及 libgit2 d 绑定。