大家是否也习惯将常用到的Python软件包放在一个头文件里?

 

01 Python头文件


使用Python编程的时候,是否大家也习惯将常引用的工具包放在一个头文件line?

我的工作中,经常使用到math, clipboard,random等,一级自己编写的基础头文件都放在一个headm.py文件中,平时使用的时候只要通过 from headm import * 便可以使用了。

#-------------------------------------------------------------
#!/usr/local/bin/python
# -*- coding: gbk -*-

import sys, os
sys.path.append(r'd:\python\teasoft')
STDFILE = open(r'd:\python\std.txt', 'a', 1)
sysstderr = sys.stderr
sysstdout = sys.stdout
sys.stderr = STDFILE
sys.stdout = STDFILE

from threading import Thread
import time, math, winsound, clipboard, random
from numpy import *

from tsmodule.tspdata   import *
from tsmodule.tspyt     import *
from tsmodule.tscmd     import *
from tsmodule.tsdopop   import *
from tsmodule.tsdraw    import *
import tsmodule.tsconfig
#------------------------------------------------------------
import matplotlib.pyplot as plt

def setpltrange(posx=2000, posy=550, width=800, height=480):
    cmfw = plt.get_current_fig_manager().window
    cmfw.setGeometry(posx, posy, width, height)

setpltrange()
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
#------------------------------------------------------------

都可以,
你理解你想做什么就可以