简体   繁体   中英

cmd error while using python code

I am new to the process of learning programming. So I am going to learn Python for my first scripting language. I downloaded Python 3.6.2 and wrote the simple "hello world " program in IDLE- it works just fine

And then I tried to open the file in command prompt and it was showing a syntax error as the below.

C:\Users\User>cd \Code

C:\Users\User>cd \Code

C:\Code>
C:\Code>hello.py


  File "C:\Code\hello.py", line 1


 Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32
             ^


SyntaxError: invalid syntax

C:\Code>

my pc is a windows 10 and 64 bits

I searched for the solution and I couldn't find any. Please reply me if you have a solution

thank you!!

I'm not familiar with Windows cmd, but in Linux, we usually run python from terminal as

python3 filename.py

or make filename.py an executable and run ./filename.py

when you want to run a python file using cmd, you have to prefix python to execute your program.
In this case, type python hello.py and see the magic!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM