English 中文(简体)
为什么可以把一个功能重新推到底?
原标题:Why can t i re-run a function in python?
  • 时间:2012-01-15 04:03:18
  •  标签:
  • python-3.x

我刚刚结束我的家事作家方案,现在我确实存在问题。

我这样说,当一项职能完成时,我询问它是否希望重新履行主要职能,而当时,它却履行不同的职能(如果用文字uck忙的话),那么这一职能根本就没有任何作用。 是否有东西可以做?

Here is my code

agenda=open("agenda.txt","a") #open the notepad file
def choice(): #pick the period
    choice=input("type write, read, or clear
")

    if choice=="read":
        read()
    elif choice=="write":
        write()
    elif choice=="clear":
        clear()
    else:
        print("Invalid Choice")


def write(): #write the homework
    per=input("What period is it")
    hw=input("What is the homework")
    if per=="1":
        agenda.write("Period 1:")
        agenda.write(hw)
        agenda.write("
")
    elif per=="2":
        agenda.write("Period 2:")
        agenda.write(hw)
        agenda.write("
")
    elif per=="3":
        agenda.write("Period 3:")
        agenda.write(hw)
        agenda.write("
")
    elif per=="4":
        agenda.write("Period 4:")
        agenda.write(hw)
        agenda.write("
")
    elif per=="5":
        agenda.write("Period 5:")
        agenda.write(hw)
        agenda.write("
")
    elif per=="6":
        agenda.write("Period 6:")
        agenda.write(hw)
        agenda.write("
")
    elif per=="7":
        agenda.write("Period 7:")
        agenda.write(hw)
        agenda.write("
")
    elif per=="8":
        agenda.write("Period 8:")
        agenda.write(hw)
        agenda.write("
")
    else:
        print("Non existant period")
    again=input("Would you like to read the homework, clear, or read again? (yes or no)")
    if again=="yes":
        choice()
    elif again=="no":
        print("
")



def clear():#clear the whole thing
   ajenda = open( agenda.txt ,  r+ )
   ajenda.truncate()
   again=input("Would you like to read the homework, clear, or read again? (yes or no)")
   if again=="yes":
       choice()
   elif again=="no":
       print("
")

def read():#read the homework
    read=open("agenda.txt","r")
    readf=read.read()
    print(readf)
    read.close
    again=input("Would you like to read the homework, clear, or read again? (yes or no)")
    if again=="yes":
        choice()
    elif again=="no":
        print("
")

choice()
agenda.close()
最佳回答

I ran your code in python2.7 because I don t have python3 right now.

我的猜测是你掌握你的法典,撰写了一些家庭工作,然后请大家阅读,不作任何显示。 当你写到档案时,出于业绩原因,在提供一定数量的数据或到你结束档案之前,缓冲区就没有进入档案。

如果你测试你的代码,然后退出方案,你将找到你的数据。 您可考虑在书写方法中增加一个插图。

问题回答

暂无回答




相关问题
Get webpage contents with Python?

I m using Python 3.1, if that helps. Anyways, I m trying to get the contents of this webpage. I Googled for a little bit and tried different things, but they didn t work. I m guessing that this ...

What is internal representation of string in Python 3.x

In Python 3.x, a string consists of items of Unicode ordinal. (See the quotation from the language reference below.) What is the internal representation of Unicode string? Is it UTF-16? The items ...

What does Python s builtin __build_class__ do?

In Python 3.1, there is a new builtin function I don t know in the builtins module: __build_class__(...) __build_class__(func, name, *bases, metaclass=None, **kwds) -> class Internal ...

what functional tools remain in Python 3k?

I have have read several entries regarding dropping several functional functions from future python, including map and reduce. What is the official policy regarding functional extensions? is lambda ...

Building executables for Python 3 and PyQt

I built a rather simple application in Python 3.1 using PyQt4. Being done, I want the application to be distributed to computers without either of those installed. I almost exclusively care about ...

热门标签