如何在另一个函数中调用函数?

时间:2012-01-18 13:43:43

标签: python

我想在另一个函数中调用一个函数。这是怎么回事?

#=========#=========#=========#=========#
def text_file():
    filename = 'text.txt'
    return filename

#=========#=========#=========#=========#
def show_log():  ##  Main log function, 
    #filename = 'text.txt'
    if not os.path.exists(text_file()): # if text.txt does not exists than create one
        file(text_file(), 'w').close()

    if os.path.getsize(text_file()) > 0: # if text.txt is not empty show the menu
        log_menu()
    else: # if text.txt is empty
        print
        print "  You have not draw anything yet!"
        print
        raw_input('  Press Enter to continue ')
    return

2 个答案:

答案 0 :(得分:2)

试试这个,我清理了一点代码。希望它有意义。

def text_file():
    return 'text.txt'

def show_log():  ##  Main log function, 
    filename = text_file()
    if os.path.exists(filename) and os.path.getsize(filename): # if text.txt is not empty show the menu
        log_menu()
    else: # no textfile there or its empty
        print
        print "  You have not draw anything yet!"
        print
        raw_input('  Press Enter to continue ')
    return

答案 1 :(得分:0)

与其他任何地方相同。

filename = text_file()