2012-01-18 84 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() 
相关问题