Python打印函数

标签 python printing python-3.x

前段时间开始学Python,第一道题就上来了。这是代码:

fh = open('/usr/share/dict/words')
for line in fh.readlines():
    print(line, end='')

当我在终端 (OS X) 中执行它时,它告诉我 invalid syntax 错误,其中放置了 end 等号。这里有什么问题?没有找到解决方案...

我从这个 page 安装了 Python 3.3.0 , Python 3.3.0 Mac OS X 64 位/32 位 x86-64/i386 安装程序

抱歉问了这么傻的问题:(

最佳答案

Python 3 安装程序不会使 Python 3 成为默认的 Python(如果这样做,它会破坏大量内容,因为很少有 Python 脚本与 Python 3 兼容)。因此,要获得 Python 3,您应该将脚本作为 python3 script.py 执行,或者将 #!/usr/bin/env python3 添加到文件顶部。

关于Python打印函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12757832/

相关文章:

python - 为什么 FreezeGun 不能使用 SQLAlchemy 默认值?

python - 关于python的sqlite3中create table and transaction的问题

Android USB 权限对话框从不出现

Python:如何在一行中打印所有条件的结果

python - 如何使用 python 3 从 back4app 检索对象?

python - Matplotlib 使用 for 循环显示多个图像

python - 转换数据帧以在 flask python 中返回为 "application-json"

javascript - window.print() javascript 在 chrome 中无法预览

python - 如果特定键的值相同,则合并字典

python-3.x - tensorflow 估计器 API :How to get weights of each node of a trained model using estimator api of tensorflow