python调试方法(其一)
<一> 这里记录一些python调试的方法:
# coding=UTF-8
''' python debug method 1
use print function to get output informatino
'''
DEBUG = True
def _debug_(*args, **kwds):
''' depends on DEBUG value, print some function '''
global DEBUG
if DEBUG:
print(args, kwds)
if __name__ == "__main__":
_debug_("this is a test")
最常见的调试方法了。print可以依据需求调整为其他的方式(logging输出日志或者直接输出到文件中均可)。
·2min·李岩
python调试方法(其一)shell-访问字符串同名变量
考虑以下场景:
期望通过给定的变量名称var_str,打印出该名称对应的变量值${var_str}。使用指令eval可以很方便的实现:
var_str="1213";
ned_param_name="var_str";
eval echo '$'"${ned_param_name}";
输出结果为1213;
·1min·李岩
shell-访问字符串同名变量lisp-do循环
lisp中,do循环形象如下:
(do (variable-definition*)
(end-test-form result-form*)
statement*);
·1min·李岩
lisp-do循环lisp-let变量声明
lisp声明、使用变量的一种方法,是使用let语句。
形如:
;(let ((variable declare1) (variable declare2) (...))
; (varaible used here));
(defun foo(x)
(format t "Parameter: ~a~%" x)
(let ((x 2))
(format t "Outer LET: ~a~%" x)
(let ((x 3))
(format t "Inner LET: ~a~%" x))
(format t "Outer LET: ~a~%" x))
(format t "Parameter: ~a~%" x));
(foo 10);
·1min·李岩
lisp-let变量声明lisp-lambda函数
lisp中的lambda表达式,显然和python中的很相似。
参照《实用common lisp编程》:
;按照 min max, 步长step为参数的fn计算的长度输出 *
(defun plot (fn min max step)
(loop for i from min to max by step do
(loop repeat (funcall fn i) do (format t "*"))
(format t "~%")))
(plot #'exp 0 4 1/2);
(plot #'(lambda (x) (* 2 x)) 0 10 1);
·1min·李岩
lisp-lambda函数clisp编译
·1min·李岩
clisp编译