Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Avik Chakraborty
6,621 PointsTried to write out event list to a text file....something is not right its printing the whole array in the text.
Tried to write out event list to a text file....something is not right its printing the whole array in the text.
will write what the software does
Describe the rules
Get items from user
Stop when asked
Chec data
def intro():
print("My to-do list.\nType in the events.\n=============================")
def rules():
print("""Type SHOW to see list.
Type DONE to print data.
Type HELP for help.""")
def lister(listOfevents):
for event in listOfevents:
print(event)
def writeExport(listOfevents):
shoplista=open("FILE01.txt",'w')
shoplista.write(str(listOfevents))
shoplista.close()
def main():
listOfevents = []
while True:
events = raw_input("===>>")
if events == "HELP":
rules()
continue
elif events == "SHOW":
lister(listOfevents)
continue
elif events =="DONE":
writeExport(listOfevents)
break
myList = listOfevents.append(events)
intro()
print("Enter the events:")
main()
2 Answers
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Avik
Your writeExport function just coverts the list to a string and then writes thats out. Why not iterate through the list and write each event to the file like below. Also I would change the mode from 'w' to 'a' i.e append to the file.
def writeExport(listOfevents):
shoplista=open("FILE01.txt",'a')
for event in listOfevents:
shoplista.write(event+"\n")
shoplista.close()
let me know if this works
Avik Chakraborty
6,621 PointsVery helpful.......thanks!!!!