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

How to run python script on linux?

青灯夜游
Release: 2019-05-23 18:54:05
Original
25694 people have browsed it

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
Copy after login

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    #为脚本增加执行权限
Copy after login

Then execute:

./test.py
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template