相关疑难解决方法(0)

Python 2.7中的旧式和新式类?

可能重复:
Python中的旧样式和新样式类

Python 2.7中新式和旧式类的当前状态是什么?我不经常使用Python,但我依旧记得这个问题.文档似乎根本没有提到这个问题:Python教程:类.我还需要担心吗?一般来说,我应该声明我的类:

class MyClass:
    pass
Run Code Online (Sandbox Code Playgroud)

要么?

class MyClass(object):
    pass
Run Code Online (Sandbox Code Playgroud)

python class new-style-class python-2.7

24
推荐指数
2
解决办法
7618
查看次数

Python中的递归?RuntimeError:调用Python对象时超出了最大递归深度

可能重复:
最大递归深度?

我的代码有另一个问题.我正在研究我在Vpython中的第一个程序,我必须模拟混合两种气体.首先我遇到了边界问题,但现在当球(代表气体粒子)留在边界内时,存在不同的错误.几秒钟后,我收到一个错误,该错误显示在我的函数的源代码下面.码:

def MovingTheBall(listOfBalls,position,numCell,flagOfExecution):
    flag = 0
    if flagOfExecution==0:
        positionTmp = position
    else:
        positionTmp = (position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0)
    for i in range( 0, len(listOfBalls) ):
        if positionTmp==listOfBalls[i].pos:
            flag=1


    if flag==1:
        return MovingTheBall(lista,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
    else:
        if positionTmp[0]==0 or positionTmp[0]>=numCell or positionTmp[0]<=-numCell or positionTmp[1]>=numCell or positionTmp[1]<=-numCell:
            return MovingTheBall(lista,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)

        return positionTmp
Run Code Online (Sandbox Code Playgroud)

错误是:

    return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
  File "gaz.txt", line 138, in MovingTheBall
    return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
  File "gaz.txt", line 138, in MovingTheBall
    return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
  File "gaz.txt", line 138, in MovingTheBall
    return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
  File "gaz.txt", line 138, in MovingTheBall
    return …
Run Code Online (Sandbox Code Playgroud)

python simulation recursion runtime-error vpython

10
推荐指数
3
解决办法
8万
查看次数