xcode - python print syntax error -
i experimenting hilbert curves written in python in xcode ide. code listing is:
# python code run hilbert curve pattern # 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 coordinates of 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 loop until renderer releases helper... while args: arg = args.split() # inputs pixels = float(arg[0]) ctype = arg[1] reps = int(arg[2]) width = float(arg[3]) # calculate number of curve cv's cvs = int(math.pow(4, reps)) # begin renderman curve statement print 'basis \"b-spline\" 1 \"b-spline\" 1' print 'curves \"%s\" [%s] \"nonperiodic\" \"p\" [' % (ctype, cvs) # create curve hilbert(0.0, 0.0, 1.0, 0.0, 0.0, 1.0, reps) # end curve statement print '] \"constantwidth\" [%s]' % width # tell renderer have finished sys.stdout.write('\377') sys.stdout.flush() # read next set of inputs args = sys.stdin.readline() if __name__ == "__main__": main()
i getting following error xcode: file "/users/248239j/desktop/hilbert/hilbertexe.py", line 12 print '%s %s' % (x, y) ^ syntaxerror: invalid syntax
would have alternative code line. in advance. started using python today.
that's problem different python-versions.
seems code written python2.x you're trying run python3.x.
the solution either use 2to3 change these small differences automatically:
2to3 /users/248239j/desktop/hilbert/hilbertexe.py
or manually replace occurences of print <string>
print(<string>)
(see print function more explanations).
or install python2.x , run code python-version
python2 /users/248239j/desktop/hilbert/hilbertexe.py
Comments
Post a Comment