小编van*_*ath的帖子

舍入到最接近的整数

我一直试图围绕长浮点数,如:

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)

python

194
推荐指数
7
解决办法
34万
查看次数

Python langdetect:只选择一种语言或另一种语言

langdetect用来确定一组字符串的语言,我知道这些字符串是英语或法语.

有时,langdetect告诉我语言是罗马尼亚语,因为我知道这是一个法语字符串.

我怎样才能langdetect选择英语或法语,而不是所有其他语言?

谢谢!

python nlp language-detection

7
推荐指数
2
解决办法
6054
查看次数

Python SSL:WRONG_VERSION_NUMBER (_ssl.c:590) 使用带有代理的 urllib

这段代码过去可以完美运行。我没有更改任何内容,但尝试从代理后面的其他位置使用它,但出现此错误:

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)

python ssl proxy urllib

5
推荐指数
0
解决办法
2997
查看次数

另一个函数内部的 Flask Celery update_state

我想从另一个函数更新我的 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 - 在后台启动 some_python_script.handle

@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)

some_python_script.handle:

def handle(param1, param2):
    param1 + param2
    # many, many different things
Run Code Online (Sandbox Code Playgroud)

理想情况下,我希望能够 self.update_state celery 任务,以便我可以轻松地从我的应用程序请求其状态,如下所示:

some_python_script.handle(理想情况下):

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)

celery flask celery-task

5
推荐指数
1
解决办法
1280
查看次数

标签 统计

python ×3

celery ×1

celery-task ×1

flask ×1

language-detection ×1

nlp ×1

proxy ×1

ssl ×1

urllib ×1