我正在尝试掌握 python 类的东西,并且我编写了这个接受用户输入的小脚本:
import sys
class Uttenhaler_setup:
Fbol=5.01333e-10
c=2.99792458e+8
L=1000
star_list=[]
dusty_models=np.array([]) #array of all the dusty models
incoming_stars='' #List of incoming stars
def __init__(self):
"""Initiates the below modules."""
self.star_catalog()
self.InputKey()
def star_catalog(self):
"""Imports the star catalog"""
try:
star_catalog=raw_input('Input pathname of stellar catalog: ')
with open(star_catalog) as incoming_stars:
for line in incoming_stars.readlines():
x=[item for item in line.split()]
self.star_list.append(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()
if __name__=='__main__':
Uttenhaler_setup()
我似乎找不到正确的语法来在我的方法之外打印 self.star_list 的结果。只是想找人指出我的错误。谢谢。