Run a python program

Source: Internet
Author: User


1 Running a python program under Windows

1) Run the Python script from the DOS command line

Using Python interpreter to execute Python script, under Windows Python interpreter is python.exe, my Python file is installed in D:\Python27, in this directory you can see the Python interpreter.

The complete command should be:

Python interpreter. py file

Both the interpreter and the Py file contain the full path. The interpreter path is indicated in the environment variable since idle is installed in the Windows environment. So just run:

Python. py file (full path)

For example: hello.py files are placed under the D:\Python27\code folder and run as follows:

Python D:\Python27\code\hello.py

or advanced to the directory where Hello files are located D:\Python27\code, and then run:

Python hello.py

2) Edit the running program in the integrated development environment

Edit the file in idle: New window, save, execute.

3) Double-click Run

Under Windows, A. py file can be run directly by double-clicking.





2,linux Running the Python program


1) write code and run in idle, just like windows

2) Run the program in the command line, similar to DOS, enter the directory where the. py file is located, executed with the Python interpreter:




3) Let the script run like a normal program


Specify the location of the Python interpreter in the first line of the. py file: Plus:

#!/usr/bin/env python

You can use the./hello.py to execute the program directly in the same directory as the. py file:



Summarize:

Describes how to run Python programs under Windows and Linux.

Run a python program

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.