Python 尝试将字符串与某些列表索引的值连接起来

Python 尝试将字符串与某些列表索引的值连接起来,python,python-2.7,Python,Python 2.7,我正在进行一个“扑克风格”游戏的自我项目,我遇到了一个错误,我需要向玩家显示玩家的手,为此,我将玩家以及他们的手存储在一个列表中,我试图通过以下方式将两者连接起来: print ('%s hand is: %s' % str(players[0]), str(hands[0,2])) ^ # edit: I have realized I was pulling from an incorrect source, modif

我正在进行一个“扑克风格”游戏的自我项目,我遇到了一个错误,我需要向玩家显示玩家的手,为此,我将玩家以及他们的手存储在一个列表中,我试图通过以下方式将两者连接起来:

print ('%s hand is: %s' % str(players[0]), str(hands[0,2]))
                                    ^ # edit: I have realized I was pulling from an incorrect source, modifying threw a new error I will detail below.
# player[] being the list of players
# and hands[] being the list of values pulled to represent cards
接近这条线时,我遇到的错误是:

Traceback (most recent call last):
  File "C:/.../poker.py", line 78, in <module>
    poker()
  File "C:/.../poker.py", line 73, in poker
    print ('%s hand is: %s' % str(player[0]), str(hands[0,2]))
TypeError: 'int' object has no attribute '__getitem__'
在多次阅读之后,我发现了一个bug,它来自于我之前发布的错误警报,并记录了那里发生的事情。我从错误的来源提取数据,并已修复此问题。但是,现在,在这样做时,我遇到了一个新的错误,我将在这里详细说明:


最后,我为这篇文章的不一致性道歉,如果我能做更多的事情来否定反对票,请让我知道。谢谢。

您的代码中出现了一些错误。我相信,这应该能够做你想做的事情-

print ('%s hand is: %s' %(str(player[0]),str(hands[0][2])))

你得到的错误表明

TypeError: 'int' object has no attribute '__getitem__'
“\uuuu getitem\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

这意味着您正在尝试对int而不是列表应用索引运算符[]。这意味着手牌或球员都不是名单

检查TypeError是否也告诉您正在处理的对象的类型,它是一个“int”对象。Int或integer表示此对象是整数

在Python中声明集合的一些很酷的方法如下:

my_list = [item0, item1, item2]
my_tuple = (some_item, other_item, yet_another_item)
my_dictionary = {'apple': 'Manzana', 'good': 'Bueno'} 

其中my_dictionary['good']将返回'Bueno',my_list[1]将返回item1。

您需要与我们共享player和hands变量的内容,以及您希望从中获得的值。看起来问题出在hands[0,2]上,但目前我不确定您想要达到什么目的。实际上,他需要编辑整个问题的内容,他将player或hands声明为整数,Python解释器试图从整数而不是列表中获取项目。printplayer[0]和printhands[0,2]是什么意思print?@Nick你搜索了你得到的错误TypeError:“int”对象没有属性“getitem”我访问了这个页面,阅读了关于参数的信息,现在我明白了为什么它只拉一个值,第一个值在模后传递给它,然后我去修复它,遇到了另一个错误,我不确定它是否会让我按照如下方式执行操作:print“%s”%example[0,2],因为它会说我确定等同于列表索引的内容必须是整数,而不是元组。
TypeError: 'int' object has no attribute '__getitem__'
my_list = [item0, item1, item2]
my_tuple = (some_item, other_item, yet_another_item)
my_dictionary = {'apple': 'Manzana', 'good': 'Bueno'}