|  | 
 
| 
Traceback (most recent call last):
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  File "C:\Users\asus\Desktop\局基金-202318-利用TomoDD方法研究新疆天山中段地壳三维P波速度结构及地震分布特征\USTClitho2.0-main\interpVel.py", line 124, in <module>
 print >> fid, "%g %d %d %d" % ( bld, nxi, nyi, nzi )
 TypeError: unsupported operand type(s) for >>: 'builtin_function_or_method' and '_io.TextIOWrapper'. Did you mean "print(<message>, file=<output_stream>)"?
 
 用Pycharm运行一个程序,给我提示这个,咋解决呀。!!!!
 
 
这个错误是由于在Python 3中,print函数的语法有所改变导致的。在Python 2中,我们可以使用 print >> fid, "%g %d %d %d" % ( bld, nxi, nyi, nzi ) 这样的语法将输出写入到文件中。然而,在Python 3中,这种语法是不再支持的。
 要解决这个问题,您可以使用Python 3的新语法,将输出写入到文件中。您可以使用 print("%g %d %d %d" % (bld, nxi, nyi, nzi), file=fid) 来实现相同的功能。这样,输出将被写入到指定的文件中。
 
 所以,您需要将代码中的这一行:
 
 复制代码print >> fid, "%g %d %d %d" % ( bld, nxi, nyi, nzi )
修改为:
 
 复制代码print("%g %d %d %d" % (bld, nxi, nyi, nzi), file=fid)
 这样修改后,您的代码应该能够在Python 3中正常运行了。
 | 
 |