Standard code (template) for .py scripts used in Python trials. See the standard .py column below.
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.
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