我一直试图围绕长浮点数,如:
32.268907563;
32.268907563;
31.2396694215;
33.6206896552;
...
Run Code Online (Sandbox Code Playgroud)
到目前为止没有成功.我试过了math.ceil(x),math.floor(x)(虽然那会向上或向下舍入,这不是我正在寻找的)并且round(x)哪些都不起作用(仍然是浮点数).
我能做什么?
编辑:代码:
for i in widthRange:
for j in heightRange:
r, g, b = rgb_im.getpixel((i, j))
h, s, v = colorsys.rgb_to_hsv(r/255.0, g/255.0, b/255.0)
h = h * 360
int(round(h))
print(h)
Run Code Online (Sandbox Code Playgroud) 我langdetect用来确定一组字符串的语言,我知道这些字符串是英语或法语.
有时,langdetect告诉我语言是罗马尼亚语,因为我知道这是一个法语字符串.
我怎样才能langdetect选择英语或法语,而不是所有其他语言?
谢谢!
这段代码过去可以完美运行。我没有更改任何内容,但尝试从代理后面的其他位置使用它,但出现此错误:
IOError: [Errno socket error] [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:590)
Run Code Online (Sandbox Code Playgroud)
这是失败的地方:
gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
data = urllib.urlopen("https://itunes.apple.com/us/rss/topfreeapplications/limit=50/genre=" + str(category) + "/json", "download.txt", context = gcontext).read()
Run Code Online (Sandbox Code Playgroud)
我立即认为问题可能来自我正在使用的代理,但不知道如何告诉 python 也使用该代理。该线程中的解决方案对我没有帮助(同样的错误)。
这是完整的追溯:
IOError Traceback (most recent call last)
C:\Users\Nathan\App_Finder_2.0.1.py in <module>()
15 print "Checking category " + str(categoryCounter) + " of " + "23..." # progress
16 print "Opening iTunes RSS feed for top 50 English apps in category " + str(categoryCounter) + " of " + "23..." # progress …Run Code Online (Sandbox Code Playgroud) 我想从另一个函数更新我的 Celery 任务的状态。这是我现在所拥有的:
@app.route('/my-long-function', methods=['POST'])
def my_long_function():
param1 = request.form['param1']
param2 = request.form['param2']
task = outside_function.delay(param1, param2)
return task.id
Run Code Online (Sandbox Code Playgroud)
@celery.task(name='outside_function')
def outside_function(param1, param2):
with app.app_context():
some_python_script.handle(param1, param2)
Run Code Online (Sandbox Code Playgroud)
def handle(param1, param2):
param1 + param2
# many, many different things
Run Code Online (Sandbox Code Playgroud)
理想情况下,我希望能够 self.update_state celery 任务,以便我可以轻松地从我的应用程序请求其状态,如下所示:
def handle(param1, param2):
param1 + param2
# many, many different things
self.outside_function.update_state('PROGRESS', meta = {'status':'progressing'})
Run Code Online (Sandbox Code Playgroud)
@app.route('/status/<task_id>')
def taskstatus(task_id):
task = outside_function.AsyncResult(task_id)
response = {
'state': task.state,
'id': task.id,
'status' …Run Code Online (Sandbox Code Playgroud)