Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python空闲类型错误:int对象不可下标_Python 3.x - Fatal编程技术网

Python 3.x Python空闲类型错误:int对象不可下标

Python 3.x Python空闲类型错误:int对象不可下标,python-3.x,Python 3.x,我正在制作一个代码,使地图(不可见),你可以在其中移动 我已经为这个代码工作了一个星期了 它有一个打字错误 import map def basicRealm(): player=[0,0]#this is you Home=[0,0] Shops=[2,7] Park=[8,2] locations = [Home, Shops, Park] desternation=Park RealmSize = grid(10)

我正在制作一个代码,使地图(不可见),你可以在其中移动

我已经为这个代码工作了一个星期了

它有一个打字错误

import map
def basicRealm():
     player=[0,0]#this is you
     Home=[0,0]
     Shops=[2,7]
     Park=[8,2]
     locations = [Home, Shops, Park]
     desternation=Park
     RealmSize = grid(10)
     choice = input("Move north, south, east, or west?[north/south/east/west]")
     no = int(input("Number of spaces to move: "))
     if choice=='north':
        axis=y
     elif choice=='south':
        axis=y
     elif choice=='east':
        axis==x
     elif choice=='west':
        axis=x
     else:
        pass
     nothing=''
     if choice=='south' or choice=='east':
        no = 0 - no
     else:
        pass
     you_are_here = move(no, player, axis)



  basicRealm()
我要运行的地图模块是:

def atDesternation(location):
    global desternation
    if desternation==location:
        return True
    else:
        return False


def atLocation(Object,locations):
    pos = position(Object)
    for i in locations:
        if pos==i:
            return i
else:
    return None

def position(Object):
     pos = (Object[0], Object[1])
     return pos

def grid(size):
     size = ListRange(0, size)
     return size

def move(spaces, thing, axis):
        here= position(thing)
        pos = here[axis] + spaces
        return pos
结果如下:

Move north, south, east, or west?[north/south/east/west]north
Number of spaces to move: 1
Traceback (most recent call last):
File "C:\Users\lewis\Desktop\Map1.py", line 35, in <module>
   basicRealm()
File "C:\Users\lewis\Desktop\Map1.py", line 29, in basicRealm
   print(position(you_are_here))
File "C:\Users\lewis\Desktop\map.py", line 13, in position
   pos = (Object[0], Object[1])
TypeError: 'int' object is not subscriptable
>>> 
向北、向南、向东或向西移动?[北/南/东/西]向北
要移动的空间数:1
回溯(最近一次呼叫最后一次):
文件“C:\Users\lewis\Desktop\Map1.py”,第35行,在
basicrelm()
basicRealm中第29行的文件“C:\Users\lewis\Desktop\Map1.py”
打印(位置(你在这里))
文件“C:\Users\lewis\Desktop\map.py”,第13行,已就位
pos=(对象[0],对象[1])
TypeError:“int”对象不可下标
>>> 
如何解决此错误?请帮忙。
我对Python不熟悉,发现很难解决错误。

很抱歉所有的编辑,不熟悉堆栈溢出尝试阅读此答案问题是
您在这里
int
,在
位置
函数中,您试图像列表一样访问它(
pos=(对象[0],对象[1])
)@Dave你发布的代码显然不是你运行的代码。回溯指向一行
print(位置(您在这里))
,该行在您发布的代码中不存在。但是,查看
move
函数,它返回的是
int
,而不是列表。您可能打算在此处执行类似于
的操作[axis]+=spaces
,然后在此处返回
。另外,不建议命名一个模块
map
,因为它会隐藏内置函数
map
。对于所有编辑,很抱歉,新堆栈溢出尝试阅读此答案问题是
您在这里
int
,在
位置
函数中,您试图像列表一样访问它(
位置=(对象[0],Object[1])
)@Dave您发布的代码显然不是您运行的代码。回溯指向一行
print(位置(您在这里))
,该行在您发布的代码中不存在。但是,查看
move
函数,它返回的是
int
,而不是列表。您可能打算在此处执行类似于
的操作[axis]+=spaces
,然后在此处返回
。另外,不建议命名一个模块
map
,因为它会隐藏内置函数
map