python打印语法错误

python打印语法错误,python,xcode,python-3.x,hilbert-curve,Python,Xcode,Python 3.x,Hilbert Curve,我正在试验在Xcode IDE中用Python编写的Hilbert曲线。代码清单是: # python code to run the hilbert curve pattern # from http://www.fundza.com/algorithmic/space_filling/hilbert/basics/index.html import sys, math def hilbert(x0, y0, xi, xj, yi, yj, n): if n <= 0:

我正在试验在Xcode IDE中用Python编写的Hilbert曲线。代码清单是:

#  python code to run the hilbert curve pattern
#  from  http://www.fundza.com/algorithmic/space_filling/hilbert/basics/index.html
import sys, math

def hilbert(x0, y0, xi, xj, yi, yj, n):
    if n <= 0:
        X = x0 + (xi + yi)/2
        Y = y0 + (xj + yj)/2

        # Output the coordinates of the cv
        print '%s %s 0' % (X, Y)
    else:
        hilbert(x0,               y0,               yi/2, yj/2, xi/2, xj/2, n - 1)
        hilbert(x0 + xi/2,        y0 + xj/2,        xi/2, xj/2, yi/2, yj/2, n - 1)
        hilbert(x0 + xi/2 + yi/2, y0 + xj/2 + yj/2, xi/2, xj/2, yi/2, yj/2, n - 1)
        hilbert(x0 + xi/2 + yi,   y0 + xj/2 + yj,  -yi/2,-yj/2,-xi/2,-xj/2, n - 1)

def main():
    args = sys.stdin.readline()
    # Remain the loop until the renderer releases the helper...
    while args:
        arg = args.split()
        # Get the inputs
        pixels = float(arg[0])
        ctype = arg[1]
        reps = int(arg[2])
        width = float(arg[3])

        # Calculate the number of curve cv's
        cvs = int(math.pow(4, reps))

        # Begin the RenderMan curve statement
        print 'Basis \"b-spline\" 1 \"b-spline\" 1'
        print 'Curves \"%s\" [%s] \"nonperiodic\" \"P\" [' % (ctype, cvs)

        # Create the curve
        hilbert(0.0, 0.0, 1.0, 0.0, 0.0, 1.0, reps)

        # End the curve statement
        print '] \"constantwidth\" [%s]' % width

        # Tell the renderer we have finished
        sys.stdout.write('\377')
        sys.stdout.flush()

        # read the next set of inputs
        args = sys.stdin.readline()
if __name__ == "__main__":
    main()
运行希尔伯特曲线模式的python代码 #从http://www.fundza.com/algorithmic/space_filling/hilbert/basics/index.html 导入系统、数学 DEF希尔伯特(X0,Y0,席,XJ,Yi,YJ,N):
在python 3中,如果n
print
是一个函数,则必须用括号括住参数:

print ('%s %s' % X, Y)

print
在python 3中是一个函数-必须用括号括住参数:

print ('%s %s' % X, Y)

这是不同Python版本的问题。
这段代码似乎是为Python2.x编写的,但您正在尝试使用Python3.x运行它

解决方案是使用2to3自动改变这些微小差异:

2to3 /Users/248239j/Desktop/hilbert/hilbertexe.py
或者手动将出现的
print
替换为
print()
(有关更多说明,请参阅)

或者只需安装Python2.x并使用该Python版本运行代码

python2 /Users/248239j/Desktop/hilbert/hilbertexe.py

这是不同Python版本的问题。
这段代码似乎是为Python2.x编写的,但您正在尝试使用Python3.x运行它

解决方案是使用2to3自动改变这些微小差异:

2to3 /Users/248239j/Desktop/hilbert/hilbertexe.py
或者手动将出现的
print
替换为
print()
(有关更多说明,请参阅)

或者只需安装Python2.x并使用该Python版本运行代码

python2 /Users/248239j/Desktop/hilbert/hilbertexe.py
可能的重复可能的重复