Discuss / Python / 萌新求问!

萌新求问!

Topic source

King.

#1 Created at ... [Delete] [Delete and Lock User]

在切换到当前目录里,输入python hello.py之后出现如下代码,请问哪里有问题。。。

King.

#2 Created at ... [Delete] [Delete and Lock User]

  File "hello.py", line 1

    Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32

           ^

SyntaxError: invalid syntax

阿城

#3 Created at ... [Delete] [Delete and Lock User]

代码第一行

借个楼保存一下可能的解决方法,希望能帮到有需要的同学。

D:\python_work>python test.py

  File "D:\python_work\test.py", line 1

    Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep  5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)] on win32

                                ^

SyntaxError: invalid decimal literal

1. 因为这里尝试打开的.py文件是直接打开IDLE后写并保存的,需要没有IDEL文件开头的这一行才可以运行(run)

Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep  5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

2. 右上角file → new file 创建一个新的文件(注意:这里新建的文件和之前不同的是上面一行多了run的选项,且没有上面的说明),写代码并保存,再按照说的方法就可以正常打开了

D:\python_work>python test.py

finally

XXX.

#5 Created at ... [Delete] [Delete and Lock User]

请问那个目录怎么弄啊,没看懂


  • 1

Reply