用于保存字典的Json模块错误

时间:2014-06-01 11:34:39

标签: python json

我正在编写一个程序来编写我的作业。 我试图用json保存我的dicts时遇到错误,我不知道该怎么做。我真的输了。我也是一个菜鸟,所以如果可以的话,不要把任何东西发布到复杂的地方。谢谢 这是错误

    Traceback (most recent call last):
  File "Homework.py", line 12, in <module>
    json.load(f1)
  File "F:\Software\Python\lib\json\__init__.py", line 268, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "F:\Software\Python\lib\json\__init__.py", line 318, in loads
    return _default_decoder.decode(s)
  File "F:\Software\Python\lib\json\decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "F:\Software\Python\lib\json\decoder.py", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)

如果你想要我的整个代码(还没有完成,它会遗漏很多)

#insert date to rate urgency of the tasks
#BLOCK 1:1
print("today's date, month(insert month number)")
ThisMonth = input(">>>")
print("today's date, day(insert day number)")
ThisDay = input(">>>")

#BLOCK 1:2
#import dictionaries
import  json
with open('LessonOut.txt', 'r') as f1:
 json.load(f1)
with open('ExercisesOut.txt', 'r') as f2:
 json.load(f2)
with open('AssignmentOut.txt', 'r') as f3:
 json.load(f3)
#BLOCK 1:5
#everything will be in a while true loop for it to run smoothly until stopped
while True:
 Input = input('>>>')

 #This is used to add a task
 #BLOCK 2:1
 if Input == 'add':
  print('Name of task?')
  Name = input('>>>')
  print('Description of task?')
  Desc = input('>>>')
  print('Rate the time it takes you to do the task on a scale from 1 to 20')
  Time = input('>>>')
  print('>>>')
  Imp = input('>>>')
  print("Rate how much you want to do it on a scale from 1 to 5 (1= want to do it, 5= don't want to")
  Want = input(">>>")
  print("enter deadline (month)")
  TimeMonth = input(">>>")
  print("enter deadline (day)")
  TimeDay = input(">>>")
  print("what type of homework is it? (Lesson/Exercises/Assignment)")
  Type = input(">>>")
  #determines what type of task it is and puts it in the right dictionary

  #BLOCK 2:2
  #Used to calculate time left to finish assignment
  DayLeft = 0
  if ThisMonth > TimeMonth:
   TimeMonth = TimeMonth + 12
  if ThisMonth == ( 1 or 3 or 5 or 7 or 8 or 10 or 12 ) and TimeDay < ThisDay:
   ThisMonth = ThisMonth + 1
   DayLeft = DayLeft + ( 31 - ThisDay )
  elif ThisMonth == 1 or 3 or 5 or 7 or 8 or 10 or 12:
   ThisMonth = ThisMonth + 1
   DayLeft = DayLeft + ( TimeDay - ThisDay )

  #BLOCK 2:3
  while ThisMonth < TimeMonth:
   if ThisMonth == 1 or 3 or 5 or 7 or 8 or 10 or 12:
    ThisMonth = ThisMonth + 1
    DayLeft = DayLeft + 31
   elif ThisMonth == 4 or 6 or 9 or 11 or 16 or 18 or 21 or 23:
    ThisMonth = ThisMonth + 1
    DayLeft = DayLeft + 30
   elif ThisMonth== 2 or 14:
    ThisMonth = ThisMonth + 1
    DayLeft = DayLeft + 28

  #BLOCK 2:4
  if Type == Lesson:
   Rating = Time + Imp + Want
   Lesson.update = {DayLeft:(Name,Desc,Rating,TimeDay,TimeMonth)}
  if Type == Exercises:
   Rating = Time + Imp + Want
   Exercises.update = {DayLeft:(Name,Desc,Rating,TimeDay,TimeMonth)}
  if Type == Assignment:
   Rating = Time + Imp + Want
   Assignment.update = {DayLeft:(Name,Desc,Rating,TimeDay,TimeMonth)}

 #BLOCK 5:1
 if Input == 'quit':
  print ("are you sure you want to quit?")
  Input = input('>>>')
  if Input == 'Yes' or 'yes' or 'y' or 'Y' or 'Yse' or 'yse':
   #BLOCK 5:2
   #Save an output dictionaries
   with open('LessonOut.txt', 'w') as f1:
    json.dump(Lesson, f1)
   with open('ExercisesOut.txt', 'w') as f1:
    json.dump(Exercises, f1)
   with open('AssignmentOut.txt', 'w') as f1:
    json.dump(Assignment, f1)
   break
   break
   break

0 个答案:

没有答案