求教大神!python中引号老是SyntaxError: invalid syntax

Garland1213 2019-02-28 01:35:05
做一个仿真的时候引号老是语法错误,但又不知道是哪里错了,第33行print "%d/%d t = %g" % (i, len(t), it),请教各位大神帮我看看

代码我截了一段,这里放不下了(源代码:https://github.com/aluque/strees/blob/master/grow_tree.py)
def main():
""" This is the main function of the code it is the starting point of
a simulation. """

# Load input parameters from the input file and add the, in allcaps
# to the global namespace.
global EXTERNAL_FIELD_VECTOR, ELECTRODE
parameters = load_input(sys.argv[1], param_descriptors)
globals().update(dict((key.upper(), item)
for key, item in parameters.iteritems()))
if RANDOM_SEED >= 0:
seed(RANDOM_SEED)

EXTERNAL_FIELD_VECTOR = array([0.0, 0.0, EXTERNAL_FIELD])
ELECTRODE = init_electrode()

# init a tree from scratch
tr, r0, q0 = init_from_scratch(INITIAL_NODES)

dt = TIME_STEP
t = r_[0:END_TIME:dt]

r, q = r0, q0

dfile = DataFile(OUT_FILE, parameters=parameters)
branched = False

for i, it in enumerate(t):
# with ContextTimer("plotting"):
# plot_projections(r, q)
# pylab.savefig('tree_%.3d.png' % i)
# print 't = %g\ttree_%.3d.png' % (it, i)
print "%d/%d t = %g" % (i, len(t), it)
branch_prob = BRANCHING_PROBABILITY

if SINGLE_BRANCHING_TIME > 0:
if it > SINGLE_BRANCHING_TIME:
if not branched:
branch_prob = inf
branched = True

if SINGLE_BRANCHING_Z != 0 and not branched:
zterm = r[tr.terminals()[0], Z]
if zterm < SINGLE_BRANCHING_Z:
if not branched:
branch_prob = inf
branched = True

r, q = adapt_step(tr, r, q, dt, p=branch_prob)

with ContextTimer("saving %d" % i):
phi = solve_phi(r, q)
dfile.add_step(it, tr, r, q, phi,
error=error, error_dq=error_dq)

if END_WITH_RECONNECTION and tr.reconnects(r):
print "Finishing due to a reconnection."
break
...全文
718 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Garland1213 2019-02-28
  • 打赏
  • 举报
回复
引用 5 楼 陈年椰子 的回复:
[quote=引用 4 楼 Garland1213 的回复:] [quote=引用 3 楼 陈年椰子 的回复:] 你的是python 3? print("{}/{}t = {}".format(i, len(t), it))
哇解决啦!大神厉害!请问我是python3.7的,这个语法上是有什么区别吗[/quote] print 方法有区别 python2 print 'aaa' print('aaa') 都可以用 python3 只能用 print('aaa')[/quote] 嗯明白了,谢谢大神!
陈年椰子 2019-02-28
  • 打赏
  • 举报
回复
引用 4 楼 Garland1213 的回复:
[quote=引用 3 楼 陈年椰子 的回复:]
你的是python 3?

print("{}/{}t = {}".format(i, len(t), it))


哇解决啦!大神厉害!请问我是python3.7的,这个语法上是有什么区别吗[/quote]

print 方法有区别
python2
print 'aaa'
print('aaa')
都可以用

python3
只能用
print('aaa')
Garland1213 2019-02-28
  • 打赏
  • 举报
回复
引用 3 楼 陈年椰子 的回复:
你的是python 3? print("{}/{}t = {}".format(i, len(t), it))
哇解决啦!大神厉害!请问我是python3.7的,这个语法上是有什么区别吗
陈年椰子 2019-02-28
  • 打赏
  • 举报
回复
你的是python 3?

print("{}/{}t = {}".format(i, len(t), it))
Garland1213 2019-02-28
  • 打赏
  • 举报
回复
引用 1 楼 陈年椰子 的回复:
print "%d/%d t = %g" % (i, len(t), it) 改成 print "{}/{}t = {}".format(i, len(t), it) 这样试试
还是不行啊,一样的错误
陈年椰子 2019-02-28
  • 打赏
  • 举报
回复
print "%d/%d t = %g" % (i, len(t), it)
改成

print "{}/{}t = {}".format(i, len(t), it)

这样试试

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧