Python 将输出结果从导入模块函数发送到文本文件

Python 将输出结果从导入模块函数发送到文本文件,python,Python,我想将结果输出打印到文件中,而不被导入模块覆盖(def主功能包含询问用户输入和计算)。但在我运行导入文件后,打印模块主功能的输出后,文件部分没有出现。导入的第一部分是检查用户输入的错误数据。 模块.py def apple_amount: app=int(input('enter number:') return app def price_apple(app): apple_price = app*2 return apple_price def banana_

我想将结果输出打印到文件中,而不被导入模块覆盖(def主功能包含询问用户输入和计算)。但在我运行导入文件后,打印模块主功能的输出后,文件部分没有出现。导入的第一部分是检查用户输入的错误数据。 模块.py

def apple_amount:
    app=int(input('enter number:')
    return app
def price_apple(app):
    apple_price = app*2
    return apple_price
def banana_amount:
    ...
    return bana
def price_ban(bana):
    ...
    return banana_price
def main():
    apples = apple_amount()
    total_apple_price = price_apple(apples)
    bananas = banana_amount()
    total_banana_price = price_banana(bananas)
    total_price = final_price(apples,bananas)
 
    print('You bought $%d or apples and $%d of bananas. Your final bill is $%d.' %(total_apple_price,total_banana_price,total_price))



import module as fr
try:
    print(fr.main()) 
except ValueError:
    print("This is not a number!")
filename = input("Enter file name: ")
try:
    f = open(filename, "w")
    f.write()
    f.close()
except FileNotFoundError:
    print("File not found")

请首先,我们想复制/粘贴它,其次,搜索引擎无法索引这些信息。因此,请确保所有文本信息都是以文本形式提供的。听起来您希望module.py返回字符串,而不是将字符串打印到标准输出。return“'您购买了$%d个苹果和$%d个香蕉。您的最终账单是$%d.%(苹果总价、香蕉总价、总价)