Home>Article>Backend Development> How to run python script on linux?

How to run python script on linux?

青灯夜游
青灯夜游 Original
2019-05-20 11:54:38 25549browse

How to run python script on linux?

How to run python script on linux:

1. Command line execution:

Establish A test.py document in which python code is written. After that, execute on the command line:

python test.py

Note: python can be written as the absolute path of python. Use which python to query.

Notes:

1). The absolute path of the file needs to be specified;

2). The output must be specified in the source code, such as print

2. UNIX script:

After creating the test.py file, you need to add the python execution path to the head of the source code, such as "#!/usr/bin/python". Among them, "#!" is called "hash bang".

After that, first change the text permission to the executable file, execute the following statement:

chmod +x test.py #为脚本增加执行权限

Then execute:

./test.py

Because in linux, python Programs such as shell are all in ordinary text format and require a program to interpret and execute them. Either specify it when calling, or specify it in the file header.

The above is the detailed content of How to run python script on linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn