prompt.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:Gilgamesh 作者: AndreaOrru 项目源码 文件源码
def run(self):
        """Run the command interpreter."""
        readline.parse_and_bind('')

        while True:
            line = input('>>> ').strip()

            # Redirect output to a file:
            try:
                separator_index = line.index('>')
                command = line[:separator_index]
                redirect_file = line[separator_index + 1:].strip()
            # Output to stdout:
            except ValueError:
                command = line
                redirect_file = None
            command = [x.strip() for x in command.split()]

            if redirect_file:
                with open(redirect_file, 'w') as f:
                    with redirect_stdout(f):
                        self._dispatch_command(command[0], command[1:])
            else:
                self._dispatch_command(command[0], command[1:])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号