Zuletzt aktiv 1731421149

Änderung a9cf32fdddd4a01d28c914fdf802d83ec7ca23e7

TastyHint3.md Orginalformat

I'm struggling to see where we take the user input for the task name.

the command variable will have exit or whatever, right?

and the new <task> will actually look like new Buy Milk

so take the string and split it into a list of strings, breaking each string on the character.

txt = "welcome to the jungle"

x = txt.split()

print(x)

# ['welcome', 'to', 'the', 'jungle']

BUT Ulas says

txt = "new Buy Milk"
t = txt.split()
print(t)
command = t[0]
rest = t[1:]
rest = " ".join(rest)
print(command, ' - ', rest)

and after hacking a bit in the python interpreter, you may end up with

  line = input(prompt)
  #print(line)
  while not line:
    line = input(prompt)
  words = line.split()
  #print(words)
  command = words[0]
  #print(command)
  rest = words[1:]
  rest = " ".join(rest)
  #print(rest)

and maybe the right thing to do is to change the command = input("Tasty> ") to something like command, rest = tasty.prompt_user("Tasty> ")

then all the "words" after the "new" will be what you pull together to name the task?

so prompt-user(self, prompt) becomes a method which asks for the user's input (using input(prompt))

def prompt_user(self, prompt):
  inp = input(prompt)
  # lookup how to split words into words[]

saving? a Hint

with open("saved_data.json", "w") as fp:
  json.dump(self.tasks,fp)