我正在尝试使用matplotlib创建一个带有图例的图表.我可以看到正在创建绘图,但图像边界不允许显示整个图例.
lines = []
ax = plt.subplot(111)
for filename in args:
lines.append(plt.plot(y_axis, x_axis, colors[colorcycle], linestyle='steps-pre', label=filename))
ax.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
Run Code Online (Sandbox Code Playgroud)
这会产生:

我正在使用Python.我已经看过如何在firefox中使用selenium禁用javascript?表示要创建配置文件,然后使用该配置文件加载驱动程序.但我想在页面渲染后禁用Javascript,这意味着我无法重新创建驱动程序.
我尝试过以下方法:
browser = selenium.webdriver.Firefox()
browser.get('http://wwwhatever.com')
browser.firefox_profile.set_preference('javascript.enabled', False)
browser.firefox_profile.update_preferences()
Run Code Online (Sandbox Code Playgroud)
但我明白了:
print browser.capabilities['javascriptEnabled']
True
Run Code Online (Sandbox Code Playgroud)
此外,我的其余测试仍然像Javascript一样启用.
我有一个空的选择字段,其中包含我在运行时定义的选项:
myfield = SelectField('myfield', validators=[Optional()])
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用看起来像这样的GET请求:
@app.route('/', methods=['GET'])
def myresponse():
form = myform(csrf_enabled=False)
form.myfield.choices = (('', ''), ('apples', 'apples'), ('pears', 'pears'))
Run Code Online (Sandbox Code Playgroud)
然后当我尝试在空表格上验证时.(我没有GET参数去myapp.com)
if not form.validate():
return search_with_no_parameters()
else:
return search_with_parameters(form) #this gets run
Run Code Online (Sandbox Code Playgroud)
当我的search_with_parameters函数尝试使用表单变量时,它会检查以确保它form.myfield.data不是Falsey(不是空字符串).如果它不是Falsey,则使用该参数进行搜索.如果为Falsey,则忽略该参数.但是,在空表单提交时,form.myfield.data是"None"一个字符串."None"完成搜索.我可以验证"None"字符串,但我认为这首先打败了使用该模块的目的.有没有办法让它只返回一个空字符串或真正的None值?
我想运行几个 Flask 应用程序,以便......
mydomain.com正在一个目录中运行一个应用程序。
mydomain.com/app1正在另一个目录中运行另一个应用程序。
mydomain.com/app2正在第三个目录中运行第三个应用程序。
我想特别避免必须有这样的 URL 结构app1.mydomain.com
在 Apache 下这可能吗?
我正在接收的数据的时间戳可低至纳秒(我们实际上在乎)。Postgres时间戳有办法达到纳秒级吗?
我有一个名为 Item 的对象。它有 2 个字段:一个名为“created_on”的日期时间行和一个名为“days”的整数行。
我想查询多天前“几天”创建的所有对象。
这是我认为应该这样做的方式:
now = utcnow()
session.query(Item).filter(Item.created_on + Interval(timedelta(days=Item.days)) <= now)
Run Code Online (Sandbox Code Playgroud)
但我无法创建这样的时间增量。我收到此错误:
TypeError: unsupported type for timedelta minutes component: InstrumentedAttribute
Run Code Online (Sandbox Code Playgroud)
更新:
感谢 van,我应该使用内置函数。我使用的是 Mysql 5.1,所以它是timestampadd. 我的新查询是这样的:
now = utcnow()
session.query(Item).filter(func.timestampadd('DAY', Item.days, Item.created_on) <= now)
Run Code Online (Sandbox Code Playgroud)
但是,我得到的新错误是:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''DAY', items.days, items.created_on) <= '2015-07-12 ' at line 3
Run Code Online (Sandbox Code Playgroud) 我有一个相当简单的问题.我正在尝试创建一个通过引用接受地图并迭代地图键的函数.
#include <map>
#include <string>
#include <sys/types.h>
using namespace std;
void update_fold_score_map(string subfold,
int32_t index,
int32_t subfold_score,
map<string, int32_t> &fold_scores){
for(map<string, int32_t>::iterator i = fold_scores.begin();
i != fold_scores.end();
i ++){
string current_substring;
string fold;
fold = (*i);
current_substring = fold.substr(index, subfold.size());
if (current_substring == subfold){
if (fold_scores[fold] < subfold_score){
fold_scores[fold] = subfold_score;
}
return;
}
}
}
int main(){
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是,我在"fold =(*i);"行收到错误 其中说明:
compilemap.cpp:16:15: error: no match for ‘operator=’ in ‘fold = i.std::_Rb_tree_iterator<_Tp>::operator* [with _Tp = std::pair<const std::basic_string<char>, …Run Code Online (Sandbox Code Playgroud) 我正在使用Python 2.7.
假设我有一个这样的列表:
string_list = ['hello', 'apple', 'green', 'paint', 'sting']
Run Code Online (Sandbox Code Playgroud)
其中列表中的每个字符串长度相同.
我想创建一个类似于以下代码的生成器:
for i in xrange(len(string_list)):
my_gen = (ch for a_string[i] in string_list)
Run Code Online (Sandbox Code Playgroud)
所以第一次运行时,my_gen会有'h','a','g','p',s'.下一次运行它会有'e','p','r','a','t'.
说明after_request"从Flask 0.7开始,如果发生未处理的异常,可能不会在请求结束时执行此函数".有没有办法改变这个,所以after_request即使是未处理的异常,也会调用函数,例如记录回溯?
python ×6
flask ×2
apache ×1
c++ ×1
matplotlib ×1
mysql ×1
postgresql ×1
sqlalchemy ×1
timedelta ×1
wtforms ×1