我应该在我的.vimrc
文件中写什么来测试我是运行vim还是gvim.
因为 颜色架构colorscheme我非常喜欢在vim中很漂亮,但在gvim中很难看.所以我想要的是,当我在vim时,我使用上述内容颜色架构 colorscheme,当我在gvim时,使用另一个 颜色架构 色彩方案.
是否有任何vimscript代码可以实现此功能?
# coding: utf-8
def func():
print 'x is', x
#x = 2 #if I add this line, there will be an error, why?
print 'Changed local x to', x
x = 50
func()
print 'Value of x is', x
Run Code Online (Sandbox Code Playgroud)
global x
in func函数,但它仍然可以找到x
50,为什么?x=2
在func函数中添加行时,会出现error(UnboundLocalError: local variable 'x' referenced before assignment
),为什么?正如logger.setLevel文档所说:
创建记录器时,级别设置为NOTSET(当记录器是根记录器时会导致处理所有消息,或者当记录器是非root记录器时委托给父级).请注意,根记录器是使用级别WARNING创建的.
所以我想如果我用级别NOTSET创建一个根记录器,将显示调试和信息日志.
代码使用basicConfig将根记录器的级别设置为NOTSET是正确的:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
logging.basicConfig(level=logging.NOTSET)
log = logging.getLogger()
log.debug('debug')
log.info('info')
log.warning('warning')
log.error('error')
log.critical('critical')
Run Code Online (Sandbox Code Playgroud)
输出是:
DEBUG:root:debug
INFO:root:info
WARNING:root:warning
ERROR:root:error
CRITICAL:root:critical
Run Code Online (Sandbox Code Playgroud)
但是如果我创建一个根记录器,并添加NOTSET级别的处理程序,例如:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
log = logging.getLogger()
hd = logging.StreamHandler()
hd.setLevel(logging.NOTSET)
log.addHandler(hd)
log.debug('debug')
log.info('info')
log.warning('warning')
log.error('error')
log.critical('critical')
Run Code Online (Sandbox Code Playgroud)
输出是:
warning
error
critical
Run Code Online (Sandbox Code Playgroud)
但我认为它也会输出调试和信息消息.
我想安装django 1.4,但默认安装版本是1.3.2,如何更改要安装的版本.
我只知道将dir更改为/ usr/portage/dev-python/django并安装django1.4的.ebuild
文件
还有另外一种方法吗?我读了使用标志文件但没有找到方法......
我git init --bare example.git
在本地主机中使用create git repo,用户是git。
我使用root进行git clone,使用crontab每分钟运行一次,命令是:
*/1 * * * * git --git-dir=/opt/xxx/.git --work-tree=/opt/xxx pull 1>>/tmp/git.log 2>&1
Run Code Online (Sandbox Code Playgroud)
输出日志为:
权限被拒绝(公钥,键盘交互)。
致命:无法从远程存储库读取。
请确保您具有正确的访问权限,并且存储库存在。
然后我尝试:
*/1 * * * * cd /opt/xxx/ && git pull 1>>/tmp/git2.log 2>&1
Run Code Online (Sandbox Code Playgroud)
但是输出是一样的。
如果我在命令行中运行,一切正常:
已经是最新的。
我不知道为什么不能与crontab一起运行?
我用tee log和xargs进程输出运行find命令; 偶然我忘记添加xargs
第二个管道,发现这个问题.
这个例子:
% tree
.
??? a.sh
??? home
??? localdir
??? abc_3
??? abc_6
??? mydir_1
??? mydir_2
??? mydir_3
7 directories, 1 file
Run Code Online (Sandbox Code Playgroud)
而且内容a.sh
是:
% cat a.sh
#!/bin/bash
LOG="/tmp/abc.log"
find home/localdir -name "mydir*" -type d -print | tee $LOG | echo
Run Code Online (Sandbox Code Playgroud)
如果我使用某些命令(例如echo
或)添加第二个管道ls
,则写入日志操作偶尔会失败.
这些是我跑了./a.sh
很多次的一些例子:
% bash -x ./a.sh; cat /tmp/abc.log // this tee failed
+ LOG=/tmp/abc.log
+ find home/localdir -name 'mydir*' -type d -print
+ tee /tmp/abc.log …
Run Code Online (Sandbox Code Playgroud) 我看到一篇关于不可变对象的文章.
它表示何时:
variable = immutable
将不可变赋值给变量.
例如
a = b # b is a immutable
它在这种情况下a
指的是a copy of b
,而不是reference to b
.如果是mutable
,那么a
就是a reference to b
所以:
a = 10
b = a
a =20
print (b) #b still is 10
Run Code Online (Sandbox Code Playgroud)
但在这种情况下:
a = 10
b = 10
a is b # return True
print id(10)
print id(a)
print id(b) # id(a) == id(b) == id(10)
Run Code Online (Sandbox Code Playgroud)
if a
是副本10
, …
环境:
我正在使用www.example.com
Django和nginx 的域,我想访问Django www.example.com/abc/
,但我不知道如何设置子目录.
这是nginx conf文件:
server {
listen 80;
server_name www.example.com;
error_log /var/log/nginx/xxx.error_log info;
root /home/web/abc; # this is the directory of the django program
location ~* ^.+\.(jpg|jpeg|png|gif|css|js|ico){
root /home/web/abc;
access_log off;
expires 1h;
}
location ~ /abc/ { # I want to bind the django program to the domian's subdirectory
include uwsgi_params;
uwsgi_pass 127.0.0.1:9000;
}
}
Run Code Online (Sandbox Code Playgroud)
当我打开网站时www.example.com/abc/
,django urls.py
不匹配,它只匹配网站就好^index$
.
如何修改nginx位置以将django设置为www.example.com/abc
?