python 3.x - unexpected text file output <_io.TextIOWrapper.... encoding='cp1252'> -
when run following code following output instead of file's text:
list of children's names in whatever group in alphabetical order: <_io.textiowrapper name='whatever.txt' mode='a' encoding='cp1252'>
easygui import*
i run script , using buttonboxes register children , create groups. add children groups using choiceboxes. problem arises when use 'list of children in each group' option , don't know what's causing nor how fix it. appreciated.
from easygui import* def register_child(): enter1 = enterbox(msg="enter child's first name.", title=' ', default='', strip=true, image=none, root=none) if enter1 none: main() return else: while enter1 == "" or enter1.isalpha() == false: enter1 = enterbox(msg="invalid entry. please enter child's first name using letters only.", title=' ', default='', strip=true, image=none, root=none) enter2 = enterbox(msg="enter child's last name.", title=' ', default='', strip=true, image=none, root=none) # ask user enter child's first name if enter2 none: main() return else: while enter2 == "" or enter2.isalpha() == false: enter2 = enterbox(msg="invalid entry. please enter child's last name using letters only.", title=' ', default='', strip=true, image=none, root=none) child_name = (enter1 + " " + enter2).title() file = open("children.txt", 'a') file.write(child_name + "\n") file.close() register_more_child = ccbox("would register child?", "please choose option.") if register_more_child == 1: register_child() return elif register_more_child == 0: main() return def list_children(): file = open("children.txt", 'r') # open children.txt file linelist = file.readlines() linelist.sort() # sort list alphabetically # display list print("list of children's names in alphabetical order:") line in linelist: print(line, end="") file.close() main() def list_groups(): file = open("groups.txt", 'r') # open children.txt file linelist = file.readlines() linelist.sort() # sort list alphabetically # display list print("list of groups' names in alphabetical order:") line in linelist: print(line, end="") file.close() main() return def children_in_group(): file = open("groups.txt", 'r') linelist = [line.strip() line in file] choice = choicebox("which group display?", "choose group.", choices=(linelist)) file.close() file1 = open('%s.txt' % choice, 'r') line_list = file1.readlines() line_list.sort() # sort list alphabetically # display list print("list of children's names in " + choice + " group in alphabetical order:") line in line_list: print(line, end="") file1.close() main() def add_child_to_group(): file = open("children.txt", 'r') # open children.txt file linelist = file.readlines() file.close() # linelist.sort() choice1 = choicebox('choose child enter group.', 'add child group. ', choices=linelist) if choice1 none: main() return else: file = open("groups.txt", 'r') linelist = [line.strip() line in file] choice2 = choicebox("which group add children to?", "choose group.", choices=linelist) file.close() file1 = open('%s.txt' % choice2, 'a') file1.write(str(file1) + "\n") file1.close() add_more_children_to_groups = ccbox("would add child group?", "please choose option.") if add_more_children_to_groups == 1: add_child_to_group() return elif add_more_children_to_groups == 0: main() return def create_group(): enter = enterbox(msg="enter group's name.", title='create group ') file = open("groups.txt", 'a') file.write(enter + "\n") file.close() file = open('%s.txt' % enter, 'w') file.close() more_groups = ccbox("would create group?", "please choose option.") if more_groups == 1: create_group() return else: main() return def children_menu(): title2 = "children." children_menu = ["1: register child.", "2: list of registered children."] button = buttonbox("choose option", title2, choices=children_menu) if button == children_menu[0]: register_child() if button == children_menu[1]: # user chooses option 2 children menu: list_children() def group_menu(): title3 = "groups." groups_menu = ["1: create group.", "2: list of groups.", "3: add child group.", "4: list of children in each group."] button = buttonbox("choose option", title3, choices=groups_menu) if button == groups_menu[0]: create_group() if button == groups_menu[1]: list_groups() if button == groups_menu[2]: add_child_to_group() if button == groups_menu[3]: children_in_group() def main(): title1 = "main menu." main_menu = ["1: children", "2: groups", "3: educators", "4: tags", "5: cancel"] button = buttonbox("choose option", title1, choices=main_menu) if button == main_menu[0]: children_menu() elif button == main_menu[1]: group_menu() elif button == main_menu[2]: title4 = "educators." educator_menu = ["1: register educator.", "2: list of registered educators."] button = buttonbox("choose option", title4, choices=educator_menu) elif button == main_menu[3]: button = "4" title4 = "tags." tags_menu = ["1: create tags", "2: list of tags."] button = buttonbox("choose option", title4, choices=tags_menu) else: print("you cancelled.") return main()
Comments
Post a Comment