函数参数传入和重复调用函数的使用方法

from sys import argv#利用sys.argv传入参数,argv是一个参数列表list
script,file_name,input_encoding,errors = argv

def main(language_file,encoding,errors):#主函数参数
    print(">>>>main",repr(language_file),encoding,errors)
    line = language_file.readline()
    
    if line:
        print(">>there is a line:",repr(line))
        print_line(line,encoding,errors)#调用子函数
        print(">>calling main again")
        return main(language_file,encoding,errors)#返回调用主函数
    print(">>>>exit main")

def print_line(line,encoding,errors):
    print("print line",repr(line),encoding,errors)
    next_lan = line.strip()
    return next_lan

with open(file_name) as language_file:
    main(language_file,input_encoding,errors)

你可能感兴趣的:(函数参数传入和重复调用函数的使用方法)