tania2046
V2EX  ›  问与答

[ Python ] 编程小白, Python 终端读文件 SyntaxError

  •  
  •   tania2046 · Dec 15, 2017 · 3673 views
    This topic created in 3250 days ago, the information mentioned may be changed or developed.
    初学 python
    用 sublime 编辑器,写好的文件与 python 安装目录一致
    在 poweshell 终端运行的时候,一直提示 SyntaxError: invalid syntax
    求问大神,怎么破!

    P.S.:powershell 运行路径
    1.
    >>> python input.py
    File "<stdin>", line 1
    python input.py
    ^
    SyntaxError: invalid syn

    2.
    PS C:\Users\DELL> python
    Python 3.6.4rc1 (v3.6.4rc1:3398dcb, Dec 5 2017, 20:41:32) [MSC v.1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> input.py
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    AttributeError: 'builtin_function_or_method' object has no attribute 'py'
    11 replies  •  2017-12-15 16:38:19 +08:00
    tania2046
    tania2046
    OP
    Dec 15, 2017
    1
    为什么只有点击没有回复啊!!
    moonmagian
    moonmagian
    Dec 15, 2017 via Android
    2
    直接输入 python 是进入了交互模式,正确的运行方法是 cd 到 python 的安装目录跑 python input.py
    SyntaxError 应该是没把 python 加到 PATH 里导致的
    moonmagian
    moonmagian
    Dec 15, 2017 via Android❤️1
    3
    好像 SyntaxError 也是因为进入了交互式模式,不进交互式模式就好了
    msputup
    msputup
    Dec 15, 2017❤️1
    4
    python input.py
    iridescent0rsy
    iridescent0rsy
    Dec 15, 2017 via Android
    5
    @moonmagian 对的,他在交互模式里执行了
    python abc.py
    这句应该在命令行里执行
    topbandit
    topbandit
    Dec 15, 2017❤️1
    6
    这个问题,明明是电脑小白,算不上编程小白
    Aalen
    Aalen
    Dec 15, 2017❤️1
    7
    所以我觉得你们并没说清楚。。。

    错误的做法:打开 powershell 后 输入 python 然后 python input.py

    正确的做法:打开 powershell, 进入 input.py 所在的目录, 输入 python input.py
    SingeeKing
    SingeeKing
    Dec 15, 2017❤️1
    8
    > python input.py
    tania2046
    tania2046
    OP
    Dec 15, 2017
    9
    @Aalen
    完美!已解决~
    电脑小白谢大神
    hyi
    hyi
    Dec 15, 2017 via Android
    10
    嗯,不是不可以用函数名当文件名的吗?
    tania2046
    tania2046
    OP
    Dec 15, 2017
    11
    @hyi
    嗯,我傻。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1470 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 04:21 · PVG 12:21 · LAX 20:21 · JFK 23:21
    ♥ Do have faith in what you're doing.