【发布时间】:2020-06-21 19:27:59
【问题描述】:
我一直在尝试将此 test.py 文件导入另一个 python 文件,但没有成功。
import xlrd
import term
import perpetuity
loc = "C:PycharmProjects/Life annuities/tables.xlsx" # this is the file location.
wb = xlrd.open_workbook(loc)
def tables_advance_perpetuity():
sheet = wb.sheet_by_index(0)
sheet.cell_value(0, 0)
num = int(input('enter the age of the life:'))
for i in range(sheet.nrows):
x = sheet.cell_value(i, 0)
if x == num:
dx = sheet.cell_value(num - 1, 2)
nx = sheet.cell_value(num - 1, 6)
print(dx)
print(nx)
ann = nx / dx
print(f'Annuity value is {ann}')
在尝试将 test.py 文件导入此 python 文件(interface.py)时,程序运行并退出而不导入 test.py 文件。但是,我已经能够成功导入 term.py 和 perpetuity.py 文件了
import perpetuity
import term
import test
print('Annuity options are :')
print('\t 1. Term annuities')
print('\t 2. perpetuities')
print('\t 3. deferred annuities')
print('=' * 50)
option = int(input('pick one that you want to compute: '))
print('=' * 50)
if option == 1:
toption = int(input('\t1. Payable in Advance:\n'
'\t2. Payable in Arrears:\n'
'\t3. Payable continously:\n'))
print('=' * 50)
if toption == 1:
term.Term_advance()
if toption == 2:
term.Term_arrears()
if toption == 3:
term.Term_continously()
basis = input('what is the calculation basis::\n'
'1.\t AM 92\n'
'2.\t ELT 15 MALES\n')
if basis == 1:
test.tables_advance_term()
print('end')
【问题讨论】:
-
您是否安装了
xlrd模块?错误日志是什么? -
是的 xlrd 模块已安装。在尝试从测试 .py 文件中调用任何函数时,程序就会退出