当前位置: 首页>>代码示例>>Python>>正文


Python compat.raw_input方法代码示例

本文整理汇总了Python中nltk.compat.raw_input方法的典型用法代码示例。如果您正苦于以下问题:Python compat.raw_input方法的具体用法?Python compat.raw_input怎么用?Python compat.raw_input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nltk.compat的用法示例。


在下文中一共展示了compat.raw_input方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _simple_interactive_download

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import raw_input [as 别名]
def _simple_interactive_download(self, args):
        if args:
            for arg in args:
                try: self._ds.download(arg, prefix='    ')
                except (IOError, ValueError) as e: print(e)
        else:
            while True:
                print()
                print('Download which package (l=list; x=cancel)?')
                user_input = compat.raw_input('  Identifier> ')
                if user_input.lower()=='l':
                    self._ds.list(self._ds.download_dir, header=False,
                                  more_prompt=True, skip_installed=True)
                    continue
                elif user_input.lower() in ('x', 'q', ''):
                    return
                elif user_input:
                    for id in user_input.split():
                        try: self._ds.download(id, prefix='    ')
                        except (IOError, ValueError) as e: print(e)
                    break 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:23,代码来源:downloader.py

示例2: converse

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import raw_input [as 别名]
def converse(self, quit="quit"):
        input = ""
        while input != quit:
            input = quit
            try: input = compat.raw_input(">")
            except EOFError:
                print(input)
            if input:
                while input[-1] in "!.": input = input[:-1]
                print(self.respond(input)) 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:12,代码来源:util.py

示例3: list

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import raw_input [as 别名]
def list(self, download_dir=None, show_packages=True,
             show_collections=True, header=True, more_prompt=False,
             skip_installed=False):
        lines = 0 # for more_prompt
        if download_dir is None:
            download_dir = self._download_dir
            print('Using default data directory (%s)' % download_dir)
        if header:
            print('='*(26+len(self._url)))
            print(' Data server index for <%s>' % self._url)
            print('='*(26+len(self._url)))
            lines += 3 # for more_prompt
        stale = partial = False

        categories = []
        if show_packages: categories.append('packages')
        if show_collections: categories.append('collections')
        for category in categories:
            print('%s:' % category.capitalize())
            lines += 1 # for more_prompt
            for info in sorted(getattr(self, category)(), key=str):
                status = self.status(info, download_dir)
                if status == self.INSTALLED and skip_installed: continue
                if status == self.STALE: stale = True
                if status == self.PARTIAL: partial = True
                prefix = {self.INSTALLED:'*', self.STALE:'-',
                          self.PARTIAL:'P', self.NOT_INSTALLED: ' '}[status]
                name = textwrap.fill('-'*27 + (info.name or info.id),
                                     75, subsequent_indent=27*' ')[27:]
                print('  [%s] %s %s' % (prefix, info.id.ljust(20, '.'), name))
                lines += len(name.split('\n')) # for more_prompt
                if more_prompt and lines > 20:
                    user_input = compat.raw_input("Hit Enter to continue: ")
                    if (user_input.lower() in ('x', 'q')): return
                    lines = 0
            print()
        msg = '([*] marks installed packages'
        if stale: msg += '; [-] marks out-of-date or corrupt packages'
        if partial: msg += '; [P] marks partially installed collections'
        print(textwrap.fill(msg+')', subsequent_indent=' ', width=76)) 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:42,代码来源:downloader.py

示例4: run

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import raw_input [as 别名]
def run(self):
        print('NLTK Downloader')
        while True:
            self._simple_interactive_menu(
                'd) Download', 'l) List', ' u) Update', 'c) Config', 'h) Help', 'q) Quit')
            user_input = compat.raw_input('Downloader> ').strip()
            if not user_input: print(); continue
            command = user_input.lower().split()[0]
            args = user_input.split()[1:]
            try:
                if command == 'l':
                    print()
                    self._ds.list(self._ds.download_dir, header=False,
                                  more_prompt=True)
                elif command == 'h':
                    self._simple_interactive_help()
                elif command == 'c':
                    self._simple_interactive_config()
                elif command in ('q', 'x'):
                    return
                elif command == 'd':
                    self._simple_interactive_download(args)
                elif command == 'u':
                    self._simple_interactive_update()
                else:
                    print('Command %r unrecognized' % user_input)
            except compat.HTTPError as e:
                print('Error reading from server: %s'%e)
            except compat.URLError as e:
                print('Error connecting to server: %s'%e.reason)
            # try checking if user_input is a package name, &
            # downloading it?
            print() 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:35,代码来源:downloader.py

示例5: _simple_interactive_update

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import raw_input [as 别名]
def _simple_interactive_update(self):
        while True:
            stale_packages = []
            stale = partial = False
            for info in sorted(getattr(self._ds, 'packages')(), key=str):
                if self._ds.status(info) == self._ds.STALE:
                    stale_packages.append((info.id, info.name))

            print()
            if stale_packages:
                print('Will update following packages (o=ok; x=cancel)')
                for pid, pname in stale_packages:
                    name = textwrap.fill('-'*27 + (pname),
                                     75, subsequent_indent=27*' ')[27:]
                    print('  [ ] %s %s' % (pid.ljust(20, '.'), name))
                print()

                user_input = compat.raw_input('  Identifier> ')
                if user_input.lower()=='o':
                    for pid, pname in stale_packages:
                        try: self._ds.download(pid, prefix='    ')
                        except (IOError, ValueError) as e: print(e)
                    break
                elif user_input.lower() in ('x', 'q', ''):
                    return
            else:
                print('Nothing to update.')
                return 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:30,代码来源:downloader.py


注:本文中的nltk.compat.raw_input方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。