Standard .py file used in Python trials (template)-2020

Standard code (template) for .py scripts used in Python trials. See the standard .py column below.

Code style

A style in which multiple trial processes are written separately with run__main1 () etc., and run__main1 () etc. are switched by comment/comment out in the main () function to switch the function to be executed. When coding, search/jump the function name run__main1 etc. in the editor, check the switching status in themain ()function, and jump again to return to the original run__main1 function position and continue editing. ..

A function is a style that adds a brief (characteristic) description of the function to the line above the function definition, such as def func1 (the function of the comment # ○○ above x, ``. Immediately below, a style that always writes a test function (execution code whose function can be confirmed independently) like def test__func1 ():. The code of the test function is a typical usage of the function. It is still useful because it can be used as a code example to represent. The test function is a style that overwrites main, such as # main = test__func1. When executing this test function, uncomment and main = By setting test__func1, only the test function test__func1 will be executed.

The standard code of the graph of matplotlib and the standard code of speeding up numba are attached at the end, and unnecessary ones need to be deleted.

Code structure

image.png

Source code standard .py

fixed form.py



# -*- coding: utf-8 -*-

#Trial of ○○

#result: ○○

#import example: (Delete unnecessary items)
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
import numba

# sec: main

def main(): #For execution switching
    run__main1()
    # run__main2()
    # run__main3()

#Trial of ○○
def run__main1():
    #result: ○○

    # sec: config

    pass
    
    # sec: run

    pass

    # sec: draw
    
    pass

"""Console output example:
○○
"""

#Trial of ○○
def run__main2():
    pass

#Trial of ○○
def run__main3():
    pass


# sec:Function of ○○

#Function of ○○
def func1(x, #Explanation of required arguments 1
    y = 0, #Option description 1
    z = 0): #Option description 2
    pass

def test__func1():
    pass
# main = test__func1


# sec:Graph fixed form

def draw__main1():
    fig = plt.figure(tight_layout=True)
    ax = fig.add_subplot(111)
    ax.plot((0, 1), (2, 3), "r-o")
    ax.grid()
    # ax.annotate("test", xy=(0.2, 2.2), ha='left', va='top')
    # ax.axis("equal")
    # ax.legend(fontsize=9, framealpha=0.5, labelspacing=0.2)
    ax.set_xlabel("x")
    ax.set_ylabel("y")
    fig.savefig("test.png ")
    plt.show()

# sec:Numba standard

@numba.jit(nopython=True, nogil=True, cache=True) #Only the speed-up part separates the function about 50 times faster
def numba_func(x):
    pass

# sec: entry

if __name__ == "__main__": main()

Recommended Posts

Standard .py file used in Python trials (template)-2020
File operations in Python
File processing in Python
Can be used in competition pros! Python standard library
[Redash] Standard library cannot be used in python function
Download the file in Python
Transposed matrix in Python standard
Change the standard output destination to a file in Python
Use jinja2 template in excel file
File / folder path manipulation in Python
8 Frequently Used Commands in Python Django
Save the binary file in Python
Linebot creation & file sharing in Python
[Python] Basic knowledge used in AtCoder
Make standard output non-blocking in Python
Create a binary file in Python
ORC, Parquet file operations in Python
Python standard input summary that can be used in competition pro
Exclusive control with lock file in Python
[python] Frequently used techniques in machine learning
Convert psd file to png in Python
Read a Python # .txt file for a super beginner in Python with a working .py
(Note) Template file search order in Django
Write O_SYNC file in C and Python
Template for writing batch scripts in python
Read the file line by line in Python
Exclusive file access between processes in Python
[GPS] Create a kml file in Python
[Python] Read the specified line in the file
Output timing is incorrect when standard (error) output is converted to a file in Python
Get all standard inputs used in paiza and competitive programming with int (python)
Template for creating command line applications in Python
++ and-cannot be used for increment / decrement in python
Create a GIF file using Pillow in Python
File DL, byte value and delete in Python3
Read a file containing garbled lines in Python
Learn the design pattern "Template Method" in Python
Create a standard normal distribution graph in Python
Techniques often used in python short coding (Notepad)
How to create a JSON file in Python
Read table data in PDF file with Python
[Python] Implemented automation in excel file copying work
Transpose CSV file in Python Part 2: Performance measurement
Pharmaceutical company researchers summarized file scanning in Python
Keep key names case in Python standard ConfigParser
GUI (WxPython) executable file (pyInstaller) [Windows] in Python3
Code often used in Python / Django apps [prefectures]
How to output "Ketsumaimo" as standard output in Python
Create a MIDI file in Python using pretty_midi
Sample to put Python Kivy in one file
Speed evaluation of CSV file output in Python
Flatten an irregular 2D standard list in Python
Quadtree in Python --2
Python in optimization
CURL in python
Script python file
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python