我正在看上面的问题/答案,让自己很困惑
53 class First(object):
54 def __init__(self):
55 print "first"
56
57 class Second(First):
58 def __init__(self):
59 super(Second, self).__init__()
60 print "second"
61
62 class Third(First):
63 def __init__(self):
64 print "third"
65
66 class Fourth(Second, Third):
67 def __init__(self):
68 super(Fourth, self).__init__()
69 print "thats it"
Run Code Online (Sandbox Code Playgroud)
第四()
第三
秒
就是这样
53 class First(object):
54 def __init__(self):
55 print "first"
56
57 class Second(First):
58 def __init__(self):
59 #super(Second, self).__init__() <---- commented out
60 print "second"
61
62 …Run Code Online (Sandbox Code Playgroud) 假设我有一个名为Point的对象数组.
点对象具有x和y值.
为了使它更难,让我们说没有初始边界,这意味着我们想要找到的矩形区域受Point对象的限制.因此,至少有4个Point对象.
所以如果数组只有4个Point对象:Point(0,0),Point(100,0)Point(0,100)和Point(100,100),我们要返回100*100的矩形区域.
这很容易.但是考虑有超过4个Point对象的情况.你如何找到最大的矩形区域?
public int maxArea(Point[] points)
{
int area;
//do algo
return area;
}
Run Code Online (Sandbox Code Playgroud)
编辑:只是通过查看y的最小值和最大值而x不保证因为我正在寻找没有Point对象的矩形区域.所以最大矩形区域内没有任何东西
什么是将一组放入地图的最快方法?
public class mySet<T>
{
private Map<T, Integer> map;
public mySet(Set<T> set)
{
Object[] array = set.toArray();
for(int i =0; i< array.length; i++)
{
T v = (T)array[i];
map.put(v, 1);
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我只是将set转换为数组并循环遍历数组并将它们逐个放入.有没有更好的方法来做到这一点?
ab.py
from ddr import Options
debugElmo = int(Options.env['GG_DEBUG_ELMO'])
postdevElmo = int(Options.env['GG_POST_DEV_ELMO'])
Run Code Online (Sandbox Code Playgroud)
Options.py
vars_of_interest = (
'AA_PYTHON',
'GG_POST_DEV_ELMO',
'GG_DEBUG_ELMO',
)
env = dict((var, os.getenv(var, 0)) for var in vars_of_interest)
Run Code Online (Sandbox Code Playgroud)
我不确定是什么,env = dict((var, os.getenv(var, 0)) for var in vars_of_interest)因为我对python很新
在Options.py中使用python中的函数?
什么是dict()?
变量是变量int(Options.env['GG_DEBUG_ELMO'])吗?
这个错误的常见原因是什么?(没有查看代码)
我用Google搜索了它,但似乎没有任何关于此类错误的参考.
我最初的猜测是(通过查看错误消息),有一个thr/proc对该对象执行某些操作,而另一个thr/proc正在尝试关闭它.
文件对象是否有锁定机制?
我有 Redis 作为代理的芹菜应用程序。
代码由以下循环组成:
running = []
res = add.apply_async([1,2], queue='add')
running.append(res)
while running:
r = running.pop()
if r.ready():
print r.get()
else:
running.insert(0,r)
Run Code Online (Sandbox Code Playgroud)
一切正常,但是当我redis-cli进入 redis 并执行时,keys *
我看到一堆 celery-task-meta 键。
他们为什么不清理?
那些是干什么用的?
——
[编辑]
我已经阅读了 CELERY_TASK_RESULT_EXPIRES 设置。
是否可以在读取结果后立即清理Redis中的任务键,而不是等到到期时间?
我有一个叫评论的应用
评论/forms.py
from django.forms import ModelForm, Textarea
from reviews.models import Review
class ReviewForm(ModelForm):
class Meta:
model = Review
fields = ['rating', 'comment']
widgets = {
'comment': Textarea(attrs={'cols': 40, 'rows': 15}),
}
Run Code Online (Sandbox Code Playgroud)
评论/views.py
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from .models import Review, Wine
from .forms import ReviewForm
import datetime
from django.contrib.auth.decorators import login_required
@login_required
def add_review(request, wine_id):
wine = get_object_or_404(Wine, pk=wine_id)
form = ReviewForm(request.POST)
if form.is_valid():
rating = form.cleaned_data['rating']
comment = form.cleaned_data['comment']
user_name …Run Code Online (Sandbox Code Playgroud) import subprocess
child = subprocess.Popen(['python', 'simple.py'], stdin=subprocess.PIPE)
child.communicate('Alice')
Run Code Online (Sandbox Code Playgroud)
我知道你可以通过沟通与执行的脚本进行通信如何检查脚本'simple.py'是否要求用户输入?
simple.py可以要求5到10个用户输入,所以简单的硬编码communicate就不够了.
[编辑]:想要在脚本运行时解析stdout并与脚本进行通信
while True:
if child.get_stdout() == '?':
# send user input
Run Code Online (Sandbox Code Playgroud) [root@mymachine redisc]# docker run -p 6379:6379 --user myuser redisc
docker: Error response from daemon: linux spec user: unable to find user myuser: no matching entries in passwd file.
Run Code Online (Sandbox Code Playgroud)
但我可以成为主机上的myuser
[root@mymachine redisc]# sudo su myuser
[myuser@mymachine redisc]#
Run Code Online (Sandbox Code Playgroud)
我如何在容器中以myuser身份运行?
终奌站:
python test.py blah='blah'
Run Code Online (Sandbox Code Playgroud)
在test.py中
print sys.argv
['test.py', 'blah=blah'] <------------
Run Code Online (Sandbox Code Playgroud)
怎么能保持它的''或者
有没有办法知道一个arg是用""还是""包裹?