这是我的实验:
$ python
Python 2.7.5 (default, Feb 19 2014, 13:47:28)
[GCC 4.8.2 20131212 (Red Hat 4.8.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 3
>>> while True:
... a = a * a
...
^CTraceback (most recent call last):
File "<stdin>", line 2, in <module>
KeyboardInterrupt
>>> a
(seems to go on forever)
Run Code Online (Sandbox Code Playgroud)
据我所知,解释器永远在"while True:"部分循环,但为什么它会被卡住评估a?
我刚刚测试我的中间管理页面并意识到我遇到了bug 15742。以下评论似乎表明我的代码是错误的:
\n\n\n\n\n这里的问题涉及如何将“查询集”从原始操作处理程序保留到处理中间页面的 POST 的代码。在引用的博客文章中,这样做是这样的:
\n\nRun Code Online (Sandbox Code Playgroud)\n\nif not form:\n form = self.AddTagForm(initial={\'_selected_action\': request.POST.getlist(admin.ACTION_CHECKBOX_NAME)})\n此代码实际上并未使用传递到操作函数中的查询集参数,而是使用发布数据中所选操作复选框的列表,该列表仅是单个页面上的 100 个复选框。操作代码应该使用传递的 queryset\n 参数,该参数包含所有项目的完整列表,而不是\n 此发布数据。然而,Django 的文档目前显示了\xe2\x80\x8be正是这种使用 POST 数据的技术,并且应该修复该问题。
\n
那么,什么是不涉及的正确方法request.POST.getlist呢?这是我的 apply_regex 现在的样子:
# apply_regex.py\nfrom django import forms\nfrom django.shortcuts import render\nfrom django.http import HttpResponseRedirect\nfrom django.contrib.admin.helpers import ACTION_CHECKBOX_NAME\nfrom django.db import transaction\nimport re\n\nclass RegexForm(forms.Form):\n _selected_action = forms.CharField(widget=forms.MultipleHiddenInput)\n from_regex = forms.CharField(label=\'From\', required=True)\n to_regex = forms.CharField(label=\'To\', required=True)\n #flags = forms.CharField(label=\'Flags\')\n\ndef apply_regex_global(admin, request, queryset, fieldname):\n _selected_action = request.POST.getlist(ACTION_CHECKBOX_NAME)\n form = None\n …Run Code Online (Sandbox Code Playgroud) 我怎样才能轻松地从git URL中提取主机名 ssh://git@gitlab.org.net:3333/org/repo.git
u = urlparse(s)
Run Code Online (Sandbox Code Playgroud)
给我
ParseResult(scheme='ssh', netloc='git@gitlab.org.net:3333', path='/org/repo.git', params='', query='', fragment='')
Run Code Online (Sandbox Code Playgroud)
这意味着netloc最接近我想要的东西,这给我留下了令人失望的工作量.
我应该这样做
u.netloc.split('@')[1].split(':')[0]
Run Code Online (Sandbox Code Playgroud)
或者是否有一个更好地处理它的库?
我试着编译以下程序:
use std::io;
fn main() {
io::stdout().write(b"Please enter your name: ");
io::stdout().flush();
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,编译器拒绝:
error: no method named `write` found for type `std::io::Stdout` in the current scope
--> hello.rs:4:18
|
4 | io::stdout().write(b"Please enter your name: ");
| ^^^^^
|
= help: items from traits can only be used if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
= help: candidate #1: `use std::io::Write`
Run Code Online (Sandbox Code Playgroud)
我发现我需要这样做use std::io::{self, Write}; …
我希望Gitlab CI可以获取另一个项目的源代码。有没有比添加只读部署密钥并在.gitlab-ci.yml中进行设置更好的方法?
考虑这个程序:
use std::io::BufRead;
use std::io;
fn main() {
let mut n = 0;
let stdin = io::stdin();
for _ in stdin.lock().lines() {
n += 1;
}
println!("{}", n);
}
Run Code Online (Sandbox Code Playgroud)
为什么它比wc的GNU版本慢10倍?看看我如何测量它:
$ yes | dd count=1000000 | wc -l
256000000
1000000+0 records in
1000000+0 records out
512000000 bytes (512 MB, 488 MiB) copied, 1.16586 s, 439 MB/s
$ yes | dd count=1000000 | ./target/release/wc
1000000+0 records in
1000000+0 records out
512000000 bytes (512 MB, 488 MiB) copied, 41.685 s, 12.3 MB/s …Run Code Online (Sandbox Code Playgroud) 为什么这段代码会编译?
#include <vector>
using namespace std;
class A
{
virtual void a() = 0;
};
int main()
{
vector<A> a; //won't fail
//A b; //that will
}
Run Code Online (Sandbox Code Playgroud) 我找到了rustdoc命令,我有点期待它的工作方式pydoc.不幸的是,rustdoc std::io:stdin没有做我想要的.有没有办法以离线形式查看标准库文档,通过命令行或某种内置的Web服务器,如Python的pydoc允许?
我不断收到以下错误:
Traceback (most recent call last):
File "/home/d/workspace/paramiko/connect_test/main.py", line 127, in connect
cStringIO.StringIO(local_settings.RSA_KEY)
File "/home/d/virtualenv/lib/python2.7/site-packages/paramiko/client.py", line 380, in connect
look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
File "/home/d/virtualenv/lib/python2.7/site-packages/paramiko/client.py", line 603, in _auth
raise saved_exception
paramiko.ssh_exception.PasswordRequiredException: Private key file is encrypted
Run Code Online (Sandbox Code Playgroud)
关键是我添加了我想用这种方式使用的密钥,并且它没有加密:
ssh_client.connect(
node_ip, username=local_settings.USERNAME,
pkey=paramiko.RSAKey.from_private_key(
cStringIO.StringIO(local_settings.RSA_KEY)
)
)
Run Code Online (Sandbox Code Playgroud)
我认为它正在查看我的加密私钥〜/ .ssh / id_rsa。有什么办法可以阻止我这样做吗?
python ×3
rust ×3
benchmarking ×1
bittorrent ×1
c++ ×1
command-line ×1
dht ×1
django ×1
django-admin ×1
gitlab ×1
gitlab-ci ×1
kademlia ×1
paramiko ×1
parsing ×1
rustdoc ×1
url-parsing ×1
urlparse ×1
vector ×1