2012-01-18 207 views
0

我想在另一個函數中調用一個函數。它是如何完成的?如何在另一個函數中調用函數?

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

我不明白你的問題是什麼。你能更精確嗎? – 2012-01-18 13:45:17

+1

可以工作,但在show_log()開頭調用一次可能會更有效,並將其分配給本地變量。 – Gerrat 2012-01-18 13:46:22

+0

http://docs.python.org/tutorial/controlflow.html#defining-functions – 2012-01-18 13:46:32

回答

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 
+0

非常感謝。它工作完美 – emre 2012-01-18 14:52:31

0

與其他地方一樣。

filename = text_file() 
相關問題