有没有办法在matplotlib中更改轴的颜色(而不是刻度线)?我一直在浏览Axes,Axis和Artist的文档,但没有运气; matplotlib画廊也没有提示.任何的想法?
在以下几行中:
$ git tag -n1
v1.8 Tagged the day before yesterday
v1.9 Tagged yesterday
v2.0 Tagged today
$ git describe
v1.9-500-ga6a8c67
$
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释为什么"git describe"不使用v2.0标签,以及如何解决这个问题?v2.0标签已被推送,所以我猜我不能删除并重新添加它.
给出以下代码:
msg = "test"
try:
"a"[1]
except IndexError as msg:
print("Error happened")
print(msg)
Run Code Online (Sandbox Code Playgroud)
有人可以解释为什么这会导致Python 3中的以下输出?
Error happened
Traceback (most recent call last):
File "test.py", line 6, in <module>
print(msg)
NameError: name 'msg' is not defined
Run Code Online (Sandbox Code Playgroud) 我试图从multiprocessing.Process中获取一个traceback对象.不幸的是,通过管道传递异常信息不起作用,因为无法对pickback对象进行pickle:
def foo(pipe_to_parent):
try:
raise Exception('xxx')
except:
pipe_to_parent.send(sys.exc_info())
to_child, to_self = multiprocessing.Pipe()
process = multiprocessing.Process(target = foo, args = (to_self,))
process.start()
exc_info = to_child.recv()
process.join()
print traceback.format_exception(*exc_info)
to_child.close()
to_self.close()
Run Code Online (Sandbox Code Playgroud)
追溯:
Traceback (most recent call last):
File "/usr/lib/python2.6/multiprocessing/process.py", line 231, in _bootstrap
self.run()
File "/usr/lib/python2.6/multiprocessing/process.py", line 88, in run
self._target(*self._args, **self._kwargs)
File "foo", line 7, in foo
to_parent.send(sys.exc_info())
PicklingError: Can't pickle <type 'traceback'>: attribute lookup __builtin__.traceback failed
Run Code Online (Sandbox Code Playgroud)
有没有其他方法来访问异常信息?我想避免传递格式化的字符串.
我试图在Vim脚本中显示错误消息:
function! Foo()
" ...
endfunction
au BufWritePost *.py silent call Foo()
Run Code Online (Sandbox Code Playgroud)
"throw"关键字有效,但可能不是正确的方法.我找到了对"echomsg"的引用,但这没有任何影响:
echohl ErrorMsg
echomsg 'Hello World'
echohl NONE
Run Code Online (Sandbox Code Playgroud)
我也尝试写入v:statusmsg(也没有效果).任何的想法?
另外,我可能还想像throw()那样停止信号传播,即不会调用监听BufWritePost事件的其他钩子.
鉴于以下型号:
class Graph(models.Model):
owner = models.ForeignKey(User)
def __unicode__(self):
return u'%d' % self.id
class Point(models.Model):
graph = models.ForeignKey(Graph)
date = models.DateField(primary_key = True)
abs = models.FloatField(null = True)
avg = models.FloatField(null = True)
def __unicode__(self):
return u'%s' % self.date
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建一个用于编辑Points列表的表单.HTML输入标记需要设置其他属性,因此我使用以下自定义表单:
class PointForm(forms.ModelForm):
graph = forms.ModelChoiceField(queryset = Graph.objects.all(),
widget = forms.HiddenInput())
date = forms.DateField(widget = forms.HiddenInput(), label = 'date')
abs = forms.FloatField(widget = forms.TextInput(
attrs = {'class': 'abs-field'}),
required = False)
class Meta:
model = Point
fields = ('graph', 'date', 'abs') # …
Run Code Online (Sandbox Code Playgroud) 鉴于以下型号:
class Blog(models.Model):
name = models.CharField()
class Entry(models.Model):
blog = models.ForeignKey(Blog)
content = models.CharField()
Run Code Online (Sandbox Code Playgroud)
我希望将以下内容传递给模板:
blogs = Blog.objects.filter(entry__content__contains = 'foo')
result = [(blog, blog.entry_set.filter(content__contains = 'foo'))
for blog in blogs]
render_to_response('my.tmpl', {'result': result}
Run Code Online (Sandbox Code Playgroud)
但是,如果找到多个匹配条目,"Blog.objects.filter(...)"会多次返回相同的Blog对象.
你如何删除重复项?或者更好的是,我错过了将匹配列表传递给模板的更简单方法吗?
我正在尝试创建一个Web界面来搜索大量的大型配置文件(大约60000个文件,每个文件的大小在20 KB到50 MB之间).这些文件也经常更新(约3次/天).
要求:
我所研究的内容:
<xml><line number="1">test</line>...</xml>
.更新需要大约5分钟,这有点奏效,但我们仍然不满意.你会如何实现替代方案?
我正在尝试使用Go YAML v3解组以下 YAML 。
model:
name: mymodel
default-children:
- payment
pipeline:
accumulator_v1:
by-type:
type: static
value: false
result-type:
type: static
value: 3
item_v1:
amount:
type: schema-path
value: amount
start-date:
type: schema-path
value: start-date
Run Code Online (Sandbox Code Playgroud)
管道下是任意数量的订购项目。应将其解组到的结构如下所示:
type PipelineItemOption struct {
Type string
Value interface{}
}
type PipelineItem struct {
Options map[string]PipelineItemOption
}
type Model struct {
Name string
DefaultChildren []string `yaml:"default-children"`
Pipeline orderedmap[string]PipelineItem // "pseudo code"
}
Run Code Online (Sandbox Code Playgroud)
这如何与 Golang YAML v3 配合使用?在 v2 中,有 MapSlice,但在 v3 中消失了。
我正在从Django缓存中删除单个路径,如下所示:
from models import Graph
from django.http import HttpRequest
from django.utils.cache import get_cache_key
from django.db.models.signals import post_save
from django.core.cache import cache
def expire_page(path):
request = HttpRequest()
request.path = path
key = get_cache_key(request)
if cache.has_key(key):
cache.delete(key)
def invalidate_cache(sender, instance, **kwargs):
expire_page(instance.get_absolute_url())
post_save.connect(invalidate_cache, sender = Graph)
Run Code Online (Sandbox Code Playgroud)
这有效 - 但有没有办法递归删除?我的路径看起来像这样:
Run Code Online (Sandbox Code Playgroud)/graph/123 /graph/123/2009-08-01/2009-10-21
只要保存了ID为"123"的图形,就需要使两个路径的缓存无效.可以这样做吗?
我试图从.vimrc文件中运行一个shell脚本(脚本中标记了三个问题):
function! CheckMe(file)
let shellcmd = 'checkme '.a:file
" Start the command and return 0 on success.
" XXX: How do you evaluate the return code?
execute '!'.shellcmd
if !result
return 0
endif
" Ending up here, the command returned an error.
" XXX: Where to you get the output?
let pair = split(output, '\S')
let line = pair[0]
let char = pair[1]
" Jump to the errenous column and line.
" XXX: Why does this not work?
normal '/\%'.line.'l\%'.char.'c' …
Run Code Online (Sandbox Code Playgroud) 我计划向客户发送一个"家庭服务器"类型的设备,与他们的(Android或iPhone)智能手机通信.问题在于,根据其互联网服务提供商,客户没有外部可达的IPv4地址(DS-lite隧道),因此智能手机不能仅使用IPv4 DNS记录来查找服务器.
我能想到的替代方案:
使服务器使用IPv6 DynDNS服务,并使IPv6优先于智能手机上的IPv4.由于解决方案应该在客户不必注册DynDNS服务的情况下工作,因此我没有找到允许我这样做的任何服务.
设置我自己的"目录服务器",以便主服务器按间隔注册它的序列号 - 类似于DynDNS,但在应用层上通过HTTPS.然后,客户端只需在应用程序中输入序列号即可找到服务器.由于身份验证/加密要求,此解决方案比我喜欢的更难实现.
关于如何使家庭服务器可达的任何其他想法?我真的想避免运行自己的"云服务".也许某种类型的点对点网络发现?
[更新:]这是我基本上寻找的:
Home server Relay DynDNS Client
| | | |
|-------- open tunnel to port 80 ----->| | |
|<-success, listening on 192.0.2.1:80 -| | |
| | | |
|----- Register "my.ddns.net" ---------------------->| |
|<------------ "my.ddns.net" is now 192.0.2.1 -------| |
| | | |
| |<- GET http://my.ddns.net -|
|<------- GET http://my.ddns.net ----| | |
|--- HTTP response ------------------->| | |
| |----- HTTP response ------>|
Run Code Online (Sandbox Code Playgroud) django ×3
python ×3
vim ×2
caching ×1
colors ×1
duplicates ×1
dyndns ×1
exception ×1
filter ×1
forms ×1
formset ×1
git ×1
git-describe ×1
git-tag ×1
go ×1
indexing ×1
instance ×1
invalidation ×1
ipv4 ×1
ipv6 ×1
lucene ×1
matplotlib ×1
message ×1
networking ×1
path ×1
process ×1
python-3.x ×1
scoping ×1
search ×1
shell ×1
sphinx ×1
status ×1
traceback ×1
yaml ×1