问题是如何在with语句中修补实例的属性.我尝试使用以下不起作用的示例.它在评论中打印.
from mock import patch, PropertyMock
class Foo(object):
f = {'a': 1}
new_foo = Foo()
with patch.object(new_foo, 'f', new_callable=PropertyMock) as mock:
mock.return_value = {'b': 2}
print new_foo.f
# <PropertyMock name='f' id='4474801232'>
Run Code Online (Sandbox Code Playgroud) 我一直在尝试在我的可执行脚本中使用Quicklisp包.一个(平凡的)工作示例是:
#!/usr/bin/sbcl --script
(eval-when (:compile-toplevel :load-toplevel :execute)
(ql:quickload "lisp-unit")) ;as explained by another question
(defpackage :test
(:use :cl :lisp-unit))
(format t "This is a test.")
Run Code Online (Sandbox Code Playgroud)
在chmod使用此代码(调用test.lisp)的文件后,我尝试执行它.但是,我收到以下错误消息:
Unhandled SB-C::INPUT-ERROR-IN-LOAD in thread #<SB-THREAD:THREAD
"main thread" RUNNING
{1002C16923}>:
READ error during LOAD:
Package QL does not exist.
Line: 4, Column: 15, File-Position: 95
Stream: #<SB-SYS:FD-STREAM
for "file /home/koz/Documents/Programming/CL/trees/test.lisp"
{1002C19A93}>
Backtrace for: #<SB-THREAD:THREAD "main thread" RUNNING {1002C16923}>
0: ((LAMBDA NIL :IN SB-DEBUG::FUNCALL-WITH-DEBUG-IO-SYNTAX))
1: (SB-IMPL::CALL-WITH-SANE-IO-SYNTAX #<CLOSURE (LAMBDA NIL :IN SB-DEBUG::FUNCALL-WITH-DEBUG-IO-SYNTAX) {1002C2498B}>) …Run Code Online (Sandbox Code Playgroud) 如果Emacs以"--damon"启动,(frame-list)则只打开1时返回2帧
(frame-list)
(#<frame *Minibuf-1* - Emacs 24.3.50.1 0x11c7270> #<frame F1 0xb94ac8>)
Run Code Online (Sandbox Code Playgroud)
如果你启动没有守护进程标志的Emacs - 那里就没有"F1"缓冲区.
如何可靠地确定用户打开了哪些帧?有没有具体的属性?
我试图在OS X上使用notify.el,但每次都会出现下一个错误:
Symbol's value as variable is void: dbus-message-type-method-call
Run Code Online (Sandbox Code Playgroud)
emacs --debug-init给出下一个输出:
Debugger entered--Lisp error: (void-variable dbus-message-type-method-call)
dbus-call-method(:session "org.freedesktop.Notifications" "/org/freedesktop/DBus" "org.freedesktop.DBus.Peer" "Ping")
byte-code("\305^H!\203^S^@\306 \n^K\f\307\310^H&^G\202^Z^@\306 \n^K\f\307%?\207" [timeout bus service dbus-path-dbus dbus-interface-peer natnump dbus-call-method "Ping" :timeout] 8)
dbus-ping(:session "org.freedesktop.Notifications")
(and (require (quote dbus) nil t) (dbus-ping :session "org.freedesktop.Notifications"))
(cond ((executable-find "growlnotify") (quote notify-via-growl)) ((and (require (quote dbus) nil t) (dbus-ping :session "org.freedesktop.Notifications")) (defvar notify-id 0 "Current D-Bus notification$
(setq notify-method (cond ((executable-find "growlnotify") (quote notify-via-growl)) ((and (require (quote dbus) nil t) (dbus-ping :session …Run Code Online (Sandbox Code Playgroud) 我想设置一个命令来移动整个文件而不移动光标.
这是我创建的宏:
qaggVGy
Run Code Online (Sandbox Code Playgroud)
但是,这会将光标移动到文件的开头.如何在不丢失游标位置的情况下拉动整个文件?
为什么当它显然将它添加到lst时总是返回nil ???
请帮忙!
谢谢!
CL-USER 1 : 1 > (defun constants-aux (form lst)
(cond ((null form) lst)
((eq (car form) 'implies) (constants-aux (cdr form) lst))
((eq (car form) 'not) (constants-aux (cdr form) lst))
((eq (car form) 'and) (constants-aux (cdr form) lst))
((eq (car form) 'or) (constants-aux (cdr form) lst))
((atom (car form)) (print (car form)) (cons (car form) (list lst)) (delete-duplicates lst) (constants-aux (cdr form) lst))
(T (constants-aux (car form) lst) (constants-aux (cdr form) lst))))
CONSTANTS-AUX
CL-USER 2 : 1 …Run Code Online (Sandbox Code Playgroud) 我有一个关于动态构建的函数(或类似的东西)的问题.在Java中,我可以以编程方式将一些Source写入一个String,编译该字符串并像函数一样多次执行它.
想象一下,我有一些遗传算法来创建最佳代码来获取n个输入参数,根据基因组计算它们并返回m个输出参数.所以我想知道是否可能(并且我很确定它是),创建一个列表列表....包含该函数,然后使用不同的输入参数调用此函数几千次以计算错误率.
我现在需要的是一个例子,如何以编程方式创建这样的列表以及如何使用它.目前我完全陷入困境.
任何参考或例子都受到热烈欢迎.