有人知道Emacs的任何图形面包屑吗?我想让我正在编辑的文件的路径显示在某个地方的顶部.
Aspell将带有下划线或短划线的单词视为两个,例如,基于云的拼写检查为"云"和"基于".有没有办法指定单词分隔符以排除短划线和下划线?
我正在尝试Sanic并运行Hello World应用程序,除了我在请求处理程序中添加了一个睡眠:
@app.route("/")
async def test(request):
time.sleep(5)
return json({"hello": "world"})
Run Code Online (Sandbox Code Playgroud)
但是,当我运行它时,它仍会阻止每个请求:
$ python app.py
2017-02-18 19:15:22,242: INFO: Goin' Fast @ http://0.0.0.0:8000
2017-02-18 19:15:22,245: INFO: Starting worker [15867]
Run Code Online (Sandbox Code Playgroud)
在两个独立的终端:
$ time curl http://0.0.0.0:8000/
{"hello":"world"}
real 0m5.009s
user 0m0.003s
sys 0m0.001s
$ time curl http://0.0.0.0:8000/
{"hello":"world"}
real 0m9.459s
user 0m0.000s
sys 0m0.004s
Run Code Online (Sandbox Code Playgroud)
我认为Sanic的想法是能够异步处理所有请求而不是阻塞,直到一个完成处理下一个请求.我在这里错过了什么吗?
好的,这是我的问题."git rerere"比较两个文件的哈希来计算分辨率吗?也就是说,我有一个包含此标记的XML文件:
<number>12</number>
Run Code Online (Sandbox Code Playgroud)
当我遇到冲突时,这个数字通常会改为13,14等,所以我坚持:
<<<<<<<
<number>12</number>
=======
<number>13</number>
>>>>>>>
Run Code Online (Sandbox Code Playgroud)
即使数字与上次不同,是否可以重新自动解决此冲突?我总是希望它以这样的方式解决它,它需要更高的数字(例如上面的例子,13).因此,如果它记录了数字12和13的分辨率,它是否会解决与不同数字的冲突?我怀疑它不会,但不妨问.
我有以下代码:
from concurrent.futures import ThreadPoolExecutor
def spam(url, hello=None, params=None):
print(url, hello, params)
urls = [1, 2, 3, 4, 5]
params = [(6, 7), 7, ('a', 1), 9, 'ab']
with ThreadPoolExecutor(5) as executor:
res = executor.map(spam, urls, params)
Run Code Online (Sandbox Code Playgroud)
预期打印:
1 (6, 7) None
2 7 None
3 ('a', 1) None
4 9 None
5 ab None
Run Code Online (Sandbox Code Playgroud)
有没有办法告诉map函数spam使用特定的关键字参数进行调用?在此示例中,我希望将值参数传递给hello参数,而不是下一行(在这种情况下为params)。
我要解决的实际用例是将params=值传递request.get给重复URL 的调用。
使用django-filters,我看到了如何在单个查询字符串中提交多个相同类型参数的各种解决方案,例如多个 ID。他们都建议使用包含逗号分隔值列表的单独字段,例如:
http://example.com/api/cities?ids=1,2,3
Run Code Online (Sandbox Code Playgroud)
是否有使用单个参数但提交一次或多次的通用解决方案?例如:
http://example.com/api/cities?id=1&id=2&id=3
Run Code Online (Sandbox Code Playgroud)
我尝试使用MultipleChoiceFilter,但它期望定义实际选择,而我想传递任意 ID(其中一些甚至可能不存在于数据库中)。
所以在Emacs中,word-wraping被称为填充,由M-q或完成M-x fill-paragraph.有没有办法修改此函数以尊重应该不破坏的空格?例如,如果我们有以下句子:
This is a black sentence with a yellow word at the end.
Run Code Online (Sandbox Code Playgroud)
并告诉Emacs在第50号填写段落,它包装如下:
This is a black sentence with a yellow word at the
end.
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用C-u M-x shell-command-on-region和输入相同fold -sw 50,我得到以下(正确)输出:
This is a black sentence with a yellow word at
the end.
Run Code Online (Sandbox Code Playgroud)
当句子的末尾后跟括号中的某些内容时,会发生类似的问题:
This is a black sentence with a yellow word here. (This is something in parens)
Run Code Online (Sandbox Code Playgroud)
上述句子M-q以下列方式用标记50 包裹:
This is a black sentence with a yellow …Run Code Online (Sandbox Code Playgroud) 我有以下文字:
Test 123:
This is a blue car
Test:
This car is not blue
This car is yellow
Hello:
This is not a test
Run Code Online (Sandbox Code Playgroud)
我想组合一个正则表达式,它找到所有以a Test或a 开头Hello且以冒号开头的项目,以及可选的树数字编号,然后返回所有内容,直到符合相同描述的下一行.所以对于上面的文本,findall正则表达式将返回一个数组:
[("Test", "123", "\nThis is a blue car\n"),
("Test", "", "\nThis car is not blue\n\nThis car is yellow\n"),
("Hello", "", "\nThis is not a test")]
Run Code Online (Sandbox Code Playgroud)
到目前为止我得到了这个:
r = re.findall(r'^(Test|Hello) *([^:]*):$', test, re.MULTILINE)
Run Code Online (Sandbox Code Playgroud)
它根据描述匹配每一行,但我不确定如何捕获内容,直到下一行以冒号结束.有任何想法吗?
我有以下使用两个简单属性的代码:
class Text(object):
@property
def color(self):
return 'blue'
@property
def length(self):
return 22
t = Text()
print t.color
Run Code Online (Sandbox Code Playgroud)
当我运行它时,它显然返回blue. 但是我怎样才能在代码中动态更新颜色的值呢?即当我尝试做:
t = Text()
print t.color
t.color = 'red'
print t.color
Run Code Online (Sandbox Code Playgroud)
它失败并出现can't set attribute错误。有没有办法修改属性的值?
编辑:
如果上面的代码被重写为在 williamtroup 的回答中使用 setter,那么简单地将其缩短为:
class Text(object):
def __init__(self):
self.color = self.add_color()
self.length = self.add_length()
def add_color(self):
return 'blue'
def add_length(self):
return 22
Run Code Online (Sandbox Code Playgroud) 我在 Peewee 中有以下简单模型:
class SiteText(BaseModel):
url = TextField()
text = TextField()
my_counter = IntegerField()
def get_text_by_url(url):
d = [s.text for s in SiteText.select(SiteText.url == url)]
d = d[0] if len(d) > 0 else None
return d
def save_text(updates):
# updates is a dict containing, url, text, my_counter
SiteText.upsert(**updates)
def get_outage_counter(url):
c = [c.my_counter for c in SiteText.select(SiteText.url == url)]
c = c[0] if len(c) > 0 else None
return c
def set_outage_counter(url, counter):
c = SiteText.get(SiteText.url == url)
c.counter = …Run Code Online (Sandbox Code Playgroud) python ×5
emacs ×2
aspell ×1
bash ×1
breadcrumbs ×1
class ×1
concurrency ×1
conflict ×1
dictionary ×1
django ×1
git ×1
git-rerere ×1
merge ×1
peewee ×1
properties ×1
regex ×1
sanic ×1
word-wrap ×1
xml ×1