<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def open(self, event):
 """Opens a file that is specified in event.attr Parameters event.attr: Dict \tkey filepath contains file path of file to be loaded \tkey filetype contains file type of file to be loaded \tFiletypes can be pys, pysu, xls """


        filepath = event.attr["filepath"]
        try:
            filetype = event.attr["filetype"]

        except KeyError:
            try:
                file_ext = filepath.strip().split(".")[-1]
            except:
                file_ext = None

            if file_ext in ["pys", "pysu", "xls", "xlsx", "ods"]:
                filetype = file_ext
            else:
                filetype = "pys"

        type2opener = {
            "pys": (Bz2AOpen, [filepath, "r"], {"main_window":
                                                self.main_window}),
            "pysu": (AOpen, [filepath, "r"], {"main_window": self.main_window})
        }

        if xlrd is not None:
            type2opener["xls"] = \
                (xlrd.open_workbook, [filepath], {"formatting_info": True})

            type2opener["xlsx"] = \
                (xlrd.open_workbook, [filepath], {"formatting_info": False})

        if odf is not None and Ods is not None:
            type2opener["ods"] = (open, [filepath, "rb"], {})

        # Specify the interface that shall be used
        opener, op_args, op_kwargs = type2opener[filetype]
        Interface = self.type2interface[filetype]

        # Set state for file open
        self.opening = True

        try:
            with opener(*op_args, **op_kwargs) as infile:
                # Make loading safe
                self.approve(filepath)

                if xlrd is None:
                    interface_errors = (ValueError, )
                else:
                    interface_errors = (ValueError, xlrd.biffh.XLRDError)

                try:
                    wx.BeginBusyCursor()
                    self.grid.Disable()
                    self.clear()
                    interface = Interface(self.grid.code_array, infile)
                    interface.to_code_array()
                    self.grid.main_window.macro_panel.codetext_ctrl.SetText(
                        self.grid.code_array.macros)

                except interface_errors, err:
                    post_command_event(self.main_window, self.StatusBarMsg,
                                       text=str(err))

                finally:
                    self.grid.GetTable().ResetView()
                    post_command_event(self.main_window, self.ResizeGridMsg,
                                       shape=self.grid.code_array.shape)
                    self.grid.Enable()
                    wx.EndBusyCursor()

                # Execute macros
                self.main_window.actions.execute_macros()

                self.grid.GetTable().ResetView()
                self.grid.ForceRefresh()

                # File sucessfully opened. Approve again to show status.
                self.approve(filepath)

                # Change current directory to file directory
                filedir = os.path.dirname(filepath)
                os.chdir(filedir)

        except IOError, err:
            txt = _("Error opening file {filepath}:").format(filepath=filepath)
            txt += " " + str(err)
            post_command_event(self.main_window, self.StatusBarMsg, text=txt)

            return False

        except EOFError:
            # Normally on empty grids
            pass

        finally:
            # Unset state for file open
            self.opening = False