Automatically execute python file

Overview

When you are playing with Python, you may occasionally want to run python automatically. Therefore, I would like to introduce how to execute the python file automatically after making a memorandum. The main method is to create and execute ** .bat file ** on Windows and ** create and execute ShellScript ** on Mac. Neither requires the installation of special software, so you can feel free to do it. If anyone knows a better way than these, it would be greatly appreciated if you could comment.

table of contents

  1. Automatically executed 1.1. Windows Edition 1.2. Mac (Linux series) 1.3 Windows bonus edition reference

1. Automatically executed

1.1. Windows Edition

For Windows, create a .bat file. If you want to automatically execute the python files of test_1.py and test_2.py, create a bat file as follows. To create a bat file, simply write the following code using a suitable text editor, and finally change the extension to .bat.

hoge.bat


python test_1.py
python test_2.py

When the bat file is created, click hoge.bat and the command prompt will be automatically launched and executed. However, please note that if the execution is a command prompt, it will close without permission when the process is completed. It is recommended to make the log spit out. If you're a regular PowerShell user, you can just drag it into PowerShell and press Enter.

1.2. Mac (Linux series)

The Mac does the same thing as creating a bat file in Windows. However, on Mac, it is not a bat file but an sh file. Suppose you want to autorun the test_1.py and test_2.py python files as you did for windows. For Mac, create the following sh file. To create an sh file, just write the following code using a suitable text editor and change the extension to .sh.

hoge.sh


python test_1.py
python test_2.py

For Mac, run the sh file from the terminal. You can run it by opening a terminal, going to the directory containing the sh file you just created and tapping sh hoge.sh. You can also run the sh file with ./hoge.sh by granting permissions with chmod w + x hoge.sh in the same directory.

1.3 Windows bonus edition

The last is a very unsmart way. However, I think it is strong (?) For complicated GUI operations + execution of python files. To do this, use software called UWSC. The free version is fine. If you download uwsc and start it, it will look like the one below. uwsc.PNG

This software is a convenient software that records GUI operations and executes them as they are. Press the second record button from the right or press the ALT key + F3 to start recording. If you want to play the recorded operation, press the ALT key + F1 to execute the recorded process. Also, since the stored operations can be saved as a uws file, it is convenient when you want to perform complicated GUI operations + python file execution.

reference

Basic usage of batch file Shell Script Reference UWSC Download and Usage

Recommended Posts

Automatically execute python file
Execute Python script from batch file
Script python file
Python file processing
File operations in Python
[Python] File / directory operations
[Note] File reading ~ Python ~
File processing in Python
Execute command from Python
Reading pyc file (Python 3.5.2)
File operations in Python
Execute command from python
Read Python csv file
python external file reading
Summary of python file operations
Download the file in Python
[Python] Execute unix command (subprocess)
Draw netCDF file with python
Execute external command in python
Automatically generated catch phrase [Python]
Python eval can execute statements.
Download csv file with python
Extract the xz file with python
Easy encryption of file contents (Python)
Python
Tips on Python file input / output
exec, eval to execute [python] statement
[Python] Write to csv file with Python
Save the binary file in Python
[Automation with python! ] Part 1: Setting file
Linebot creation & file sharing in Python
Automatically format Python code in Vim
Output to csv file with Python
Create an Excel file with Python3
Create a binary file in Python
Python CSV file reading and writing
Execute Python code from C # GUI
Execute Python Script during CodeSys # RunTime
Automatically build Python documentation with Sphinx
Extract the targz file using python
Notes for Python file input / output
Python memo ① Folder and file operations
Python executable file conversion module comparison 2
Python CGI file created on Windows
ORC, Parquet file operations in Python
[Automation with python! ] Part 2: File operation
[Python] File operation using if statement
Run tests automatically when saving file
File upload to Azure Storage (Python)
[Python] How to convert db file to csv
Creating a simple PowerPoint file with Python
Automatically create Python API documentation with Sphinx
Exclusive control with lock file in Python
Execute Python code on C ++ (using Boost.Python)
Read CSV file with python (Download & parse CSV file)
Execute Python script with cron of TS-220
How to convert Python to an exe file
[Python] Convert csv file delimiters to tab delimiters
Check the existence of the file with python
Convert psd file to png in Python
Automatically update Power BI Desktop in Python