import codecs
fileIN ="calendar.ics "
fileOUT="newCalendar.ics "
fd =codecs.open(fileIN,"r ","utf −8")
line=fd.readline()
head=""
#set the headers of the file in var head
while(line != "BEGIN:VEVENT\ r \n") :
head+=line
line=fd.readline()
#set all the events in a list of events
while (line!="END:VCALENDAR\ r \n") :
newEvent=line
line=fd.readline()
while(line != "END:VEVENT\ r \n") :
newEvent+=line
line=fd.readline()
newEvent+=line
line=fd.readline()
# last line
tail=line
fd.close()
#print calendar with only first event on newCalendarFile
file =codecs.open(fileOUT ,"w","utf −8")
file.write(head)
file.write(newEvent)
file.write( tail )
file.close()
我创建了一个解析器来从所有组中选择我的编程和我的实践课程! 但我在阅读脚本时遇到问题,有这条消息错误:
Traceback (most recent call last):
File "C:\Users\\Desktop\projet3.py", line 5, in <module>
fd =codecs.open(fileIN,"r ","utf −8")
File "C:\Users\\AppData\Local\Programs\Python\Python35-32\lib\codecs.py", line 895, in open
file = builtins.open(filename, mode, buffering)
ValueError: invalid mode: 'r b'