0

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
4
  • 2
    I don't understand what your problem is. Can you be more precise? Commented Jan 18, 2012 at 13:45
  • 1
    that works, but it might be more efficient to just call it once at the beginning of show_log(), and assign it to a local variable. Commented Jan 18, 2012 at 13:46
  • docs.python.org/tutorial/controlflow.html#defining-functions Commented Jan 18, 2012 at 13:46
  • If you test before asking "Is it how it`s done?", you'll notice that you already have found out how it's done. Commented Jan 18, 2012 at 14:11

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

Comments

0

Same way as anywhere else.

filename = text_file()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.