Initialization of Python program -
i have python program stars bunch of code import modules, initialize variables , calls few functions. here's part of it:
import numpy np import scipy sp import scipy.optimize opt import scipy.constants const import random import time if os.name == 'nt': os.system('cls') if os.name == 'posix': os.system('clear') rows, columns = os.popen('stty size', 'r').read().split() inclination = math.radians(inclination) period = period*const.day
is there way can put of once single module , call it? tried put of external program , call it, understood gets done, locally, not on main code.
the idea able use "initialization module" in multiple programs.
did try putting of other .py file, , from x import *
? should have of modules , constants in whatever file called from.
edit: if you're worried performing of multiple times, don't be. on import, python checks see if module has been loaded before goes , loads module again. example have these files:
filea.py => initializer import *
fileb.py => import initializer
filec.py => import filea, fileb
when run filec.py, code in initializer.py run once, though both filea , fileb load it, , though in different ways.
Comments
Post a Comment