This code works by taking my user input and correctly pulling the information I'm giving it.
I'm having difficulty understanding the implementation of methods in classes. I'm pretty sure I'm not doing this the correct way. Can anyone show me the way it should be done?
class prog_setup:
def __init__(self):
"""Initiates the below modules/variables."""
self.get_starlist()
self.get_InputKey()
self.define_listsANDarrays()
self.determine_normalizationpoint()
self.create_fobs_fobserr()
#self.calculate_taumag()
self.search_DUSTYmodels()
self.calculate_chi2()
self.delete_null_components()
self.dust_whittet_sub()
def get_starlist(self):
"""Imports the list of stars that you would like information on."""
self.star_list=np.array([])
try:
get_star_list=raw_input('Input pathname of the list of stars to be studied: ')
incoming_stars=open(get_star_list,'rb')
for line in incoming_stars:
x=line.split()
self.star_list=np.append(self.star_list,x) #Appends the individual star-IDs to the empty array star_list.
print 'Stars imported successfully.'
except IOError:
print 'Star import unsuccessful. Check that the star catalog file-path is correct. Program exiting now.'
sys.exit()
self.indices_of_star_list=range(len(self.star_list))
def get_InputKey(self):
"""Imports the Input (.inp) file. Historically, InputUttenthaler.inp. Allows for definition
of parameters which are utilized later in the script."""
input_script=raw_input('Pathname of .inp file: ')
InputKey=[]
self.band=''
self.Ak_scalefactor=''
try:
with open(input_script) as input_key:
for line in input_key.readlines():
x=[item for item in line.split()]
InputKey.append(x)
if InputKey[0][0]=='1' or InputKey[0][0]=='2': #Checks to see if .inp file is valid or not by checking the first row/column which should be 1 or 2.
print 'Your .inp file was successfully imported'
else:
print 'Your .inp file import failed. Check the validity of your file.\n Program exiting now.'
sys.exit()
except IOError:
print 'The .inp file import was unsuccessful. Check that your file-path is valid.\n Program exiting now.'
sys.exit()
The entire code is longer; I just put in the first two methods to give an example of what my structure looks like.
prog_setup
be? \$\endgroup\$