我用google搜索"python ssh".有一个很棒的模块pexpect,它可以使用ssh(带密码)访问远程计算机.
连接远程计算机后,我可以执行其他命令.但是我无法再次在python中获得结果.
p = pexpect.spawn("ssh user@remote_computer")
print "connecting..."
p.waitnoecho()
p.sendline(my_password)
print "connected"
p.sendline("ps -ef")
p.expect(pexpect.EOF) # this will take very long time
print p.before
Run Code Online (Sandbox Code Playgroud)
如何得到ps -ef我的结果?
我在不同的文件夹中有十几个测试用例.在根目录中有一个测试运行器.
unittest\
package1\
test1.py
test2.py
package2\
test3.py
test4.py
testrunner.py
Run Code Online (Sandbox Code Playgroud)
目前,我手动将四个测试用例添加到测试套件中
import unittest
from package1.test1 import Test1
from package1.test2 import Test2
from package2.test3 import Test3
from package2.test4 import Test4
suite = unittest.TestSuite()
suite.addTests(unittest.makeSuite(Test1))
suite.addTests(unittest.makeSuite(Test2))
suite.addTests(unittest.makeSuite(Test3))
suite.addTests(unittest.makeSuite(Test4))
result = unittest.TextTestRunner(verbosity=2).run(suite)
if not result.wasSuccessful():
sys.exit(1)
Run Code Online (Sandbox Code Playgroud)
如何让测试运行器自动测试所有测试用例?如:
for testCase in findTestCases():
suite.addTests(testCase)
Run Code Online (Sandbox Code Playgroud) 我使用delphi和python实现了相同的代码(发布表单).python代码运行完美,但delphi代码失败.在python中,我可以简单地写httplib2.debuglevel=4一下,看看实际发送到服务器的内容是什么.但我不知道如何在delphi中打印内容.
def python_request_data(url, cookie, data):
httplib2.debuglevel = 4
conn = httplib2.Http()
conn.follow_all_redirects = True
headers = {'Cookie': cookie, 'Content-Type': 'application/x-www-form-urlencoded'}
response, contents = conn.request(url, 'POST', data, headers=headers)
procedure DelphiRequestData(const Url, Cookie, Data: string);
var
Client: TIdHttp;
Params: TStringList;
Response: string;
begin
Client := TIdHttp.Create(nil);
try
Client.HTTPOptions := [hoKeepOrigProtocol];
Client.Request.CustomHeaders.AddValue('Cookie', Cookie);
Params := TStringList.Create;
try
Params.QuoteChar := #0;
Params.Delimiter := '&';
Params.DelimiterText := Data;
Client.Request.ContentType := 'application/x-www-form-urlencoded';
Client.Request.ContentLength := Length(Params.DelimitedText);
Response := Client.Post(Url, Params);
finally
Params.Free;
end;
finally
Client.Free; …Run Code Online (Sandbox Code Playgroud) 在Bootstrap 3中,我可以轻松设计响应敏感的表.我可以将列拆分成他们的网格系统.不仅如此,我还可以为小型设备隐藏一些列.这是我的例子.该表有13列.前两列各有25%的宽度,其余列将共享其余50%的宽度.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<table class="table table-bordered">
<tr>
<td class="col-xs-3">1</td>
<td class="col-xs-3">2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
</tr>
</table>
</div>
</div>Run Code Online (Sandbox Code Playgroud)
上面的代码在Bootstrap 4中不起作用.您可以看到不希望列宽.我检查了他们的发行说明,它没有提到表格布局的任何重大变化.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<table class="table table-bordered">
<tr>
<td class="col-3">1</td>
<td class="col-3">2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
</tr>
</table>
</div>
</div>Run Code Online (Sandbox Code Playgroud)
现在,如果我添加style="width:25%"前两列,它将起作用.现在我想弄清楚,我的用法是否错误,或者Bootstrap 4无法指定响应列宽度.任何提示都非常感谢.
更新#1
关于@CamiloTerevinto的建议,col-xs-*现在重命名为col-*.
更新#2 我在他们的问题跟踪器中发现了一些相关的讨论:
对此的临时解决方法是设置<tr …
我在Delphi 2010中尝试了新的Record类型TTimeSpan.但我鼓励一个非常奇怪的问题.
assert(TTimeSpan.FromMilliseconds(5000).Milliseconds = 5000);
Run Code Online (Sandbox Code Playgroud)
这个断言没有通过.'TTimeSpan.FromMilliseconds(5000).Milliseconds'的值预计为5000,但它为0.
我深入挖掘:
function TTimeSpan.GetMilliseconds: Integer;
begin
Result := Integer((FTicks div TicksPerMillisecond) mod 1000);
end;
FTicks = 50000000
TicksPerMillisecond = 10000
FTick div TicksPerMillisecond = 50000000 div 10000 = 5000
(FTick div TicksPerMillisecond) mod 1000 = 5000 mod 1000 = 0 // I do not understand, why mod 1000
Integer((FTick div TicksPerMillisecond) mod 1000) = Integer(0) = 0
Run Code Online (Sandbox Code Playgroud)
我的代码解释是正确的,不是吗?
更新:方法GetTotalMilliseconds(双精度)正确实现.
我尝试使用PIL将32位位图转换为32位PNG.
from PIL import Image
im = Image.open('example.bmp')
print im.mode
# it prints 'RGB', but expected was 'RGBA'
im.save('output.png', format='PNG')
Run Code Online (Sandbox Code Playgroud)
预期的图像模式是'RGBA',但实际上我得到'RGB'.
我也尝试了以下代码,但它不起作用.
from PIL import Image
im = Image.open('example.bmp')
im = im.convert('RGBA')
im.save('output.png', format='PNG')
Run Code Online (Sandbox Code Playgroud) 我想复制带偏移的内存块,是否可能?
这是我到目前为止的代码:
const
SOURCE: array [0..5] of Byte = ($47, $49, $46, $38, $39, $61);
var
Destination: Pointer;
begin
// This is a full copy
Move(SOURCE, Destination^, SizeOf(SOURCE));
// If i want to copy from the third byte, is it possible?
// I imagine the code should be, but it cannot be compiled.
Move(Slice(SOURCE^, {Offset=}2)^, Destination^, SizeOf(SOURCE) - 2);
end;
Run Code Online (Sandbox Code Playgroud) 我bulk_create用来将1个mio记录插入到新表中.这需要80秒.Django只使用一个CPU核心(大约25%的CPU,但没有核心达到100%)我相信有改进潜力.
这是代码
class Stock(models.Model):
code = models.CharField(max_length=6, unique=True)
name = models.CharField(max_length=8)
class Watchers(models.Model):
date = models.DateField(db_index=True)
stock = models.ForeignKey(Stock, unique_for_date="date")
num = models.PositiveIntegerField(default=0)
batch = []
for input in inputs:
watcher = Watcher(date=input['date'], stock=get_stock(), num=input['num'])
batch.append(watcher)
Watcher.objects.bulk_create(batch)
Run Code Online (Sandbox Code Playgroud)
我尝试了几件事:
batch_size.对我来说最好的价值大约是4000.它需要80-90秒.ThreadPool().它慢得多,大约120-140秒DateField.比1慢一点.我正在使用MySQL 5.6社区版.存储引擎是MyISAM.这是配置.
[mysqld]
server-id = 1
default-storage-engine = MyISAM
port = 3306
socket = /tmp/mysql.sock
datadir = "{MYSQLDATAPATH}"
skip-external-locking
explicit_defaults_for_timestamp = TRUE
# MyISAM #
key-buffer-size = 32M
max_allowed_packet = 16M …Run Code Online (Sandbox Code Playgroud) 我一直在学习React 16.8的新功能。我相信React的Pure Component应该自动避免不必要的重新渲染操作。
在以下示例中,App自身本身是无状态组件。我useState用来维护两个状态对象text和nested: {text}。
有3个测试。前两个测试有效。无论有多少次,我都会更改状态,无需进行任何重新渲染操作。
现在,第三个测试尝试text使用相同的字符串值设置状态,但是引用不同。我希望什么都不会重新呈现,但是实际上,<Headline/>将会重新呈现。
我应该使用某种记忆方式来避免吗?我觉得将其存档将太多代码。并且程序员必须非常小心地编写高质量的React代码。..
class Headline extends React.PureComponent {
render() {
const {text} = this.props;
return <h1>{text} (render time: {Date.now()})</h1>;
}
}
const simpleText = 'hello world'
const App = () => {
const [text, setText] = React.useState(simpleText)
const [nested, setNested] = React.useState({text: simpleText})
return (
<div>
<Headline text={text}/>
<Headline text={nested.text}/>
<button onClick={()=>setText(simpleText)}>
test 1: the first line should not change (expected)
</button>
<button …Run Code Online (Sandbox Code Playgroud) delphi ×3
python ×3
bmp ×1
bootstrap-4 ×1
copy ×1
css ×1
debugging ×1
delphi-2010 ×1
django ×1
idhttp ×1
indy ×1
javascript ×1
linux ×1
login ×1
memory ×1
mysql ×1
node.js ×1
npm ×1
orm ×1
performance ×1
pexpect ×1
png ×1
pouchdb ×1
react-hooks ×1
reactjs ×1
record ×1
rgba ×1
ssh ×1
testcase ×1
timespan ×1
unit-testing ×1
yarnpkg ×1