简体   繁体   中英

how to call a function in another function?

I want to call a function in another function. Is it how it`s done?

#=========#=========#=========#=========#
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

Try this, i cleaned up the code a little. Hope it makes sense.

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

与其他任何地方一样。

filename = text_file()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM