Ich bin neu hier und habe eine frage zu meinem ersten script:
Code: Alles auswählen
def viewlist():
print mylist
def Addtolist():
print "Which name would you like to add?"
name = raw_input("> ")
print "What do you want to assign to", name + "?"
value = raw_input("> ")
print "OK.", name, "with the value", value, "has been added."
mylist[name] = value
def Delfromlist():
print "Which name do you want to delete?"
delname = raw_input("> ")
del mylist[delname]
print "OK.", delname, "has been removed from the list."
def loadfile():
print "Please enter the name of the file"
namefile = raw_input("> ")
namefile = namefile + ".txt"
fopen = open(namefile)
readdata = fopen.read()
fopen.close()
print readdata
print
print "Do you want to save the read data?"
print "1. Yes"
print "2. No"
print
commandread = raw_input("> ")
if commandread == "1":
print "What's the name of the data?"
datadefname = raw_input("> ")
datadefname = readdata
def savefile():
print "Please enter a name for your list."
listdefname = raw_input("> ")
listdefname = listdefname + ".txt"
print "WARNING!!! The file, if already exists, will be overwritten COMPLETELY!"
print
print "1. Overwrite"
print "2. Append"
print "Write 'exit' to exit writing"
commandnow = raw_input("> ")
#########################PROBLEM IS HERE#########################
if commandnow == "1":
f = file(listdefname, "w")
f.write(mylist)
f.close()
elif commandnow == "2":
f.append(mylist)
f. close()
#################################################################
elif commandnow != "exit" and commandnow != "1" and commandnow != "2":
print "Sorry, unkown command!"
f.close
print
print "List@Generator v0.1 Copyright by Kaan D. Ocal"
print
print "---------------------------------------------"
command = 0
mylist = {}
while command != "quit":
print
print "Please choose an action"
print
print " 1. Look at your list"
print " 2. Add a name to your list"
print " 3. Remove a name from your list"
print " 4. Load a list"
print " 5. Save your list"
print
print "Write 'quit' to quit"
print
command = raw_input("> ")
if command != "1" and command != "2" and command != "3" \
and command != "4" and command != "5" and command != "quit":
print
print "Sorry, invalid command"
elif command == "1":
viewlist()
elif command == "2":
Addtolist()
elif command == "3":
Delfromlist()
elif command == "4":
loadfile()
elif command == "5":
savefile()
Code: Alles auswählen
...
print "Which Dictionary do you want to look at?"
chosendict = raw_input("> ")
print chosendict
...
Ich würde mich freuen, wenn jemand mir helfen könnte.