我正在学习命令设计模式.据我所知,总是与命令模式相关的四个术语是命令,接收器,调用者和客户端.
具体的命令类有一个execute()方法,调用者有几个命令.调用者决定何时调用execute()命令的方法.
当execute()方法被调用时,它会调用接收器的方法.然后,接收器完成工作.
我不明白为什么我们需要接收器类?我们可以在内部工作execute(),似乎接收器类是多余的.
预先感谢.
这一直困扰着我目前的项目.我正在尝试使用XLWT将样式写入excel表,见下文:
sheet.write(rowi,coli,value,stylesheet.bold,stylesheet.bordered)
Run Code Online (Sandbox Code Playgroud)
我遇到了这个错误:
TypeError:write()最多需要5个参数(给定6个)
有没有想过如何解决这个问题,以便为某个单元添加多种样式?可以在这里做一个清单吗?
有一次,在看了Mike Muller的性能优化教程(我认为这个)之后,一个想法开始存在于我的脑海中:如果性能很重要,最小化通过索引访问循环中的项目,例如,如果您需要x[1]在循环中多次访问for x in l-为变量赋值x[1]并在循环中重用它.
现在我有了这个合成的例子:
import timeit
SEQUENCE = zip(range(1000), range(1, 1001))
def no_unpacking():
return [item[0] + item[1] for item in SEQUENCE]
def unpacking():
return [a + b for a, b in SEQUENCE]
print timeit.Timer('no_unpacking()', 'from __main__ import no_unpacking').timeit(10000)
print timeit.Timer('unpacking()', 'from __main__ import unpacking').timeit(10000)
Run Code Online (Sandbox Code Playgroud)
unpacking()和no_unpacking()函数返回相同的结果.实现方式不同:unpacking()将项目解包到循环中a和b循环中; no_unpacking()通过索引获取值.
对于python27,它显示:
1.25280499458
0.946601867676
Run Code Online (Sandbox Code Playgroud)
换言之,unpacking()表现优于no_unpacking()约25%.
问题是:
奖金问题:
pypy- …我假设这是可能的,实际上非常简单,但我是咕噜咕噜和量角器的新手,我无法在网上找到答案(也许我使用了错误的搜索条件).
我在文件中有以下e2e测试test/e2e/Recipients.js:
describe('Recipients Tab', function() {
beforeEach(function () {
browser.get('#/recipients');
});
it('should have no e-mail list', function () {
expect(element(by.css('accordion')).isPresent()).toBe(false);
});
});
Run Code Online (Sandbox Code Playgroud)
目前,我这样做:
grunt e2e
Run Code Online (Sandbox Code Playgroud)
我的量角器配置文件:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome'
},
specs: ['../e2e/**/*.js'],
baseUrl : 'http://localhost:8080/spr',
jasmineNodeOpts: {
showColors: true // Use colors in the command line report.
}
};
Run Code Online (Sandbox Code Playgroud)
当然这会运行我所有的测试,但是当我正在开发一个特定的测试时,我不想运行整个测试.我想运行这个文件.
我怎样才能做到这一点?有旗帜还是什么?
谢谢
这是带有量角器主题的Set firefox配置文件的后续内容.
根据setFirefoxProfilehowto,可以设置一个firefox配置文件,其中包含一个特殊的"helper"js代码,该代码使用firefox-profile和q库来动态编写 firefox配置文件.
这对我有用,multiCapabilities直到我尝试使用多个浏览器并配置:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
multiCapabilities: [
{
browserName: 'chrome',
specs: [
'footer.disabledCookies.spec.js'
],
chromeOptions: {
prefs: {
'profile.default_content_settings.cookies': 2
}
}
},
...
// other capabilities here
...
helper.getFirefoxProfile()
},
...
}
Run Code Online (Sandbox Code Playgroud)
使用此设置我收到一个错误(这里是完整的回溯):
规格模式与任何文件都不匹配.
据我所知,这意味着使用firefox配置文件的设置缺少specs密钥.换句话说,它找不到任何运行的测试.
我试图在帮助器本身内部包含specs到capabilities字典中,但错误仍然存在.
如果使用multiCapabilities?如何修复错误并设置firefox配置文件?
作为一种解决方法,我创建了一个单独的量角器配置文件,只配置了firefox(使用capabilities)并设置grunt …
import os
from bs4 import BeautifulSoup
do = dir_with_original_files = 'C:\FOLDER'
dm = dir_with_modified_files = 'C:\FOLDER'
for root, dirs, files in os.walk(do):
for f in files:
print f.title()
if f.endswith('~'): #you don't want to process backups
continue
original_file = os.path.join(root, f)
mf = f.split('.')
mf = ''.join(mf[:-1])+'_mod.'+mf[-1] # you can keep the same name
# if you omit the last two lines.
# They are in separate directories
# anyway. In that case, mf = f
modified_file = os.path.join(dm, mf) …Run Code Online (Sandbox Code Playgroud) 有人应该在哪里为她的 Django 项目放置任何外部 python 脚本?更合适的位置是什么(如果有的话)?她应该在主 Django 项目中创建一个文件夹并将其放在那里并将其添加到 python 路径中还是有更好的方法来处理这个问题?使用外部脚本的原因是不要使用可以在脚本文件中更好地组织并且可以为多个视图提供服务的代码来重载视图。
故事:
在Nina Zakharenko的PyCon谈论 Python内存管理期间,她解释了Python 中分代垃圾收集的工作方式,注意到:
Python维护一个程序运行时创建的每个对象的列表.实际上,它使3:
generation 0generation 1generation 2
问题:
为了更好地理解Python中的内存管理以及调试内存泄漏的目的,如何在程序运行期间观察/观察在所有3代列表中添加和删除的对象?
我查看了gc模块,但没有找到获取当前生成列表值的相关方法.
python memory debugging garbage-collection memory-management
在其中一个测试中,我们需要声明存在3个元素中的一个.目前我们正在使用protractor.promise.all()和Array.reduce():
var title = element(by.id("title")),
summary = element(by.id("summary")),
description = element(by.id("description"));
protractor.promise.all([
title.isPresent(),
summary.isPresent(),
description.isPresent()
]).then(function (arrExists) {
expect(arrExists.reduce(function(a,b) { return a || b; })).toBe(true);
});
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来解决它与Jasmine没有明确解决承诺?我们需要一个自定义匹配器,还是可以通过内置匹配器解决?
示例HTML
<h2 id="name">
ABC
<span class="numbers">123</span>
<span class="lower">abc</span>
</h2>
Run Code Online (Sandbox Code Playgroud)
我可以用以下内容获得数字:
soup.select('#name > span.numbers')[0].text
Run Code Online (Sandbox Code Playgroud)
如何ABC使用BeautifulSoup和select函数获取文本?
在这种情况下怎么样?
<div id="name">
<div id="numbers">123</div>
ABC
</div>
Run Code Online (Sandbox Code Playgroud) python ×6
javascript ×3
protractor ×3
angularjs ×2
html-parsing ×2
arrays ×1
debugging ×1
django ×1
django-views ×1
end-to-end ×1
excel ×1
firefox ×1
for-loop ×1
gruntjs ×1
html ×1
jasmine ×1
memory ×1
oop ×1
parsing ×1
performance ×1
python-2.7 ×1
selenium ×1
testing ×1
xlwt ×1