python打印语法错误

时间:2016-02-06 09:49:24

标签: python xcode python-3.x hilbert-curve

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

SELECT
l.listing_id AS id, l.category_id, l.title AS listing_title, l.description, l.address, l.city, l.zip, UNIX_TIMESTAMP(l.date_submitted) AS date_submitted, l.latitude, l.longitude,
( 6371 * acos( cos( radians(40.293861) ) * cos( radians( l.latitude) ) * cos( radians( l.longitude ) - radians(-76.600252) ) + sin( radians(40.293861) ) * sin( radians( l.latitude ) ) ) ) AS distance,
c.category_id AS cat_id, c.title AS cat_title, c.slug AS cat_slug, 
r.region_id AS region_id, r.title AS region_title, r.slug AS region_slug 
FROM listings AS l
LEFT JOIN categories AS c ON l.category_id = c.category_id 
LEFT JOIN regions AS r ON l.region_id = r.region_id 
WHERE MATCH (l.title,l.description,l.city,r.title,c.title) AGAINST `('cheesecake in pennsylvania')`

我从Xcode收到以下错误:   File" /Users/248239j/Desktop/hilbert/hilbertexe.py" ;,第12行     打印'%s%s' %(X,Y)                 ^ SyntaxError:语法无效

是否有人可以替代该代码行。提前致谢。我今天开始使用python。

2 个答案:

答案 0 :(得分:2)

在python 3中,

print ('%s %s' % X, Y) 是一个函数 - 你必须用括号括起参数:

#!/bin/bash

DIR=$(cd "$1" ; pwd)
PREFIX=
until [ "$DIR" = / ] ; do 
    echo -n "$PREFIX"$(basename "$DIR")" "$(ls -Ab "$DIR" | wc -l)
    DIR=$(dirname "$DIR")
    PREFIX=", "
done
echo

答案 1 :(得分:2)

这是不同Python版本的问题 看起来这个代码是为Python2.x编写的,但是你试图用Python3.x运行它。

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

2to3 /Users/248239j/Desktop/hilbert/hilbertexe.py

或者使用print <string>手动替换print(<string>)的出现(有关详细说明,请参阅Print is a function)。

或者只安装Python2.x并使用该Python-Version

运行代码
python2 /Users/248239j/Desktop/hilbert/hilbertexe.py
相关问题