开发者

How to delay input

First i got a menu asking what i want to do, the problem is even if i select exit i still have to input the variables from the addEntry function. How do i make it so that only when i call the addEntry function i need to input those variables?

date=raw_input('date')
amount=raw_input('amount')
desc=raw_input('desc')
account=raw_input('开发者_如何学编程account')
def addEntry(date, amount, desc, account):
        transact=open("transactions.txt", "w")
        print >>transact, date, amount, desc, account
        transact.close()


If I understand you correctly, you just want to move the calls to raw_input into addEntry, instead of making them arguments; then they only execute and prompt the user for input when addEntry is called:

def addEntry():
    date=raw_input('date')
    amount=raw_input('amount')
    desc=raw_input('desc')
    account=raw_input('account')
    transact=open("transactions.txt", "w")
    print >>transact, date, amount, desc, account
    transact.close()

You can also change whatever code is calling addEntry so it does the prompts right before the call, instead of doing them at the beginning of your application. For example:

if userClickedAddEntryButton: # <-- I made this up
    date=raw_input('date')
    amount=raw_input('amount')
    desc=raw_input('desc')
    account=raw_input('account')
    addEntry(date, amount, desc, account)        
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜