Using a terminal to execute a python program

Source: Internet
Author: User

There are two ways to execute a python file using a terminal

Mode one: Command line mode

Method Two: Python interactive mode

Command-line mode

In command-line mode, a. py file is executed, and a Python file is written in the editor, saved in the. py format, and executed in the terminal. Be sure to note that the current location is located under the location of the. py file when executing the. py file at the terminal.

Here is the direct execution of the one.py file via Python one.py, the error display is to find this file.

So the first step should be to enter the directory of this file, and then execute the. py file, as follows

Note: If you do not know the absolute path of this file, you can drag the file into the terminal, the terminal will show the path of the file

Python interactive mode

Executing the. py file using Python interactive mode first to enter Python interactive mode in the terminal

Enter the interactive mode: Enter Python in the terminal, carriage return, show the following is successfully entered the interactive mode, prompt is >>>

Exit Interaction Mode: Enter exit () in terminal, return, you can exit the current interactive mode

In Python interactive mode can be directly written Python program, but the program has not been written to save, suitable for beginners to practice practiced hand

A Python program can be written after the >>> prompt

Using a terminal to execute a python program

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.