小编Tom*_*ere的帖子

Python:线程中的TypeError.函数采用x位置参数,但给出了y

我目前正在使用Python.我有一个start-function,它从消息中获取一个字符串.我想为每条消息启动线程.

此刻的帖子应该像这样打印我的消息:

def startSuggestworker(message):
    print(message)

def start():
    while True:
        response = queue.receive_messages()
        try:
            message = response.pop()
            start_keyword = message.body
            t = threading.Thread(target=startSuggestworker, args = (start_keyword))
            t.start()
            message.delete()
        except IndexError:
            print("Messages empty")
            sleep(150)

start()
Run Code Online (Sandbox Code Playgroud)

目前我得到了一个TypeError并且不明白为什么.Exception消息是这样的:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
TypeError: startSuggestworker() takes 1 positional argument but y were given
Run Code Online (Sandbox Code Playgroud)

*y =我的字符串的长度

我究竟做错了什么?

python multithreading

10
推荐指数
1
解决办法
5747
查看次数

DynamoDB:如果 Python 中不存在密钥,我该如何执行 putItem?

我现在刚使用 Amazon AWS DynamoDB。在未来,我想将 Items 放在我的表中,但前提是具有相同键的 Item 不存在,这样我就不会覆盖现有值。你知道我是怎么做到的吗?我的代码:

from __future__ import print_function # Python 2/3 compatibility
import boto3
import json
import decimal

# Helper class to convert a DynamoDB item to JSON.
class DecimalEncoder(json.JSONEncoder):
    def default(self, o):
        if isinstance(o, decimal.Decimal):
            if o % 1 > 0:
                return float(o)
            else:
                return int(o)
        return super(DecimalEncoder, self).default(o)

dynamodb = boto3.resource('dynamodb', region_name='eu-central-1')

table = dynamodb.Table('Movies')

title = "The Big New Movie"
year = 2015

response = table.put_item(
    Item={
        'year': year,
        'title': title,
        'info': { …
Run Code Online (Sandbox Code Playgroud)

python amazon-web-services amazon-dynamodb

3
推荐指数
1
解决办法
4150
查看次数

Amazon EC2实例 - 在何处添加凭证文件?

我有一个Amazon EC2实例.在我的实例上,我想运行一个python程序.该计划试图访问其他亚马逊服务.在我的Mac上程序运行正常,因为凭证文件位于"〜/ .aws/credentials"文件夹中.但我不知道我的亚马逊EC2实例库"〜"在哪里.那么我必须在哪里提交我的凭证?希望您能够帮助我.

amazon-ec2 amazon-web-services

0
推荐指数
1
解决办法
153
查看次数