How to run py files directly in linux

How to run py files directly in linux

1. First create the file (cd to the directory where it needs to be placed)

touch myTest.py

2. Edit myTest.py

vi myTest.py

Add content inside

#! /usr/bin/env python

Then add the code you need to add

print('hello, world!')

Then enter command mode, :wq save and exit vi

3. Change the permissions of myTest.py as needed. This is mainly used for testing, so do not set it to 777

chmod 777 myTest.py

4. This is to run myTest.py directly in the current directory (similar to directly executing exe in windows)

./myTest.py

The above method of directly running py files in Linux is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • How to call Linux Shell commands under Python
  • How to run Python scripts in the CMD command line
  • Run the .py file in cmd: python steps
  • Implementation of running python files in python shell

<<:  Detailed explanation of JS ES6 coding standards

>>:  Why do select @@session.tx_read_only appear in DB in large quantities?

Blog    

Recommend

Sample code for automatic web page refresh and automatic jump

Automatic web page refresh: Add the following code...

Steps to package and deploy the Vue project to the Apache server

In the development environment, the vue project i...

Implementation of Vue large file upload and breakpoint resumable upload

Table of contents 2 solutions for file upload Bas...

vue front-end HbuliderEslint real-time verification automatic repair settings

Table of contents ESLint plugin installation in H...

Sample code for batch deployment of Nginx with Ansible

1.1 Copy the nginx installation package and insta...

How to use Cron Jobs to execute PHP regularly under Cpanel

Open the cpanel management backend, under the &qu...

Example usage of Linux compression file command zip

The ".zip" format is used to compress f...

Solution to uninstalling Python and yum in CentOs system

Background of the accident: A few days ago, due t...

What are the benefits of using // instead of http:// (adaptive https)

//Default protocol /The use of the default protoc...

Detailed explanation of how to use CMD command to operate MySql database

First: Start and stop the mysql service net stop ...