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


Python six.unicode函数代码示例

本文整理汇总了Python中six.unicode函数的典型用法代码示例。如果您正苦于以下问题:Python unicode函数的具体用法?Python unicode怎么用?Python unicode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: _from_word2vec_text

 def _from_word2vec_text(fname):
   with _open(fname, 'rb') as fin:
     words = []
     header = unicode(fin.readline())
     vocab_size, layer1_size = list(map(int, header.split())) # throws for invalid file format
     vectors = []
     for line_no, line in enumerate(fin):
       try:
         parts = unicode(line, encoding="utf-8").strip().split()
       except TypeError as e:
         parts = line.strip().split()
       except Exception as e:
         logger.warning("We ignored line number {} because of erros in parsing"
                         "\n{}".format(line_no, e))
         continue
       # We differ from Gensim implementation.
       # Our assumption that a difference of one happens because of having a
       # space in the word.
       if len(parts) == layer1_size + 1:
         word, weights = parts[0], list(map(float32, parts[1:]))
       elif len(parts) == layer1_size + 2:
         word, weights = parts[:2], list(map(float32, parts[2:]))
         word = u" ".join(word)
       else:
         logger.warning("We ignored line number {} because of unrecognized "
                         "number of columns {}".format(line_no, parts[:-layer1_size]))
         continue
       index = line_no
       words.append(word)
       vectors.append(weights)
     vectors = np.asarray(vectors, dtype=np.float32)
     return words, vectors
开发者ID:EmilStenstrom,项目名称:polyglot,代码行数:32,代码来源:embeddings.py

示例2: unknown_starttag

 def unknown_starttag(self, tag, attrs):
     # called for each start tag
     # attrs is a list of (attr, value) tuples
     # e.g. for <pre class='screen'>, tag='pre', attrs=[('class', 'screen')]
     uattrs = []
     strattrs = ''
     if attrs:
         for key, value in attrs:
             value = value.replace('>', '&gt;').replace('<', '&lt;').replace('"', '&quot;')
             value = self.bare_ampersand.sub("&amp;", value)
             # thanks to Kevin Marks for this breathtaking hack to deal with (valid) high-bit attribute values in UTF-8 feeds
             if isinstance(value, unicode):
                 try:
                     value = unicode(value, self.encoding)
                 except:
                     value = unicode(value, 'iso-8859-1')
             uattrs.append((unicode(key, self.encoding), value))
         strattrs = u''.join([u' %s="%s"' % (key, val) for key, val in uattrs])
         if self.encoding:
             try:
                 strattrs = strattrs.encode(self.encoding)
             except:
                 pass
     if tag in self.elements_no_end_tag:
         self.pieces.append('<%(tag)s%(strattrs)s />' % locals())
     else:
         self.pieces.append('<%(tag)s%(strattrs)s>' % locals())
开发者ID:AbhishekKumarSingh,项目名称:galaxy,代码行数:27,代码来源:sanitize_html.py

示例3: stream_from_fh

def stream_from_fh(fh, clean=False):
    for l in fh:
        l = l.decode('utf-8')
        try:
            yield Word.from_string(unicode(l), clean=clean)
        except ValueError as v:
            print(unicode(v).encode('utf-8'))
            continue
开发者ID:jkahn,项目名称:islex,代码行数:8,代码来源:load.py

示例4: _get_message

 def _get_message(self, run_errors, teardown_errors):
     run_msg = unicode(run_errors or '')
     td_msg = unicode(teardown_errors or '')
     if not td_msg:
         return run_msg
     if not run_msg:
         return 'Keyword teardown failed:\n%s' % td_msg
     return '%s\n\nAlso keyword teardown failed:\n%s' % (run_msg, td_msg)
开发者ID:userzimmermann,项目名称:robotframework-python3,代码行数:8,代码来源:errors.py

示例5: _parse_arguments

 def _parse_arguments(self, cli_args):
     try:
         options, arguments = self.parse_arguments(cli_args)
     except Information as msg:
         self._report_info(unicode(msg))
     except DataError as err:
         self._report_error(unicode(err), help=True, exit=True)
     else:
         self._logger.info('Arguments: %s' % ','.join(arguments))
         return options, arguments
开发者ID:userzimmermann,项目名称:robotframework-python3,代码行数:10,代码来源:application.py

示例6: dictionary_should_contain_item

    def dictionary_should_contain_item(self, dictionary, key, value, msg=None):
        """An item of `key`/`value` must be found in a `dictionary`.

        Value is converted to unicode for comparison.

        See `Lists Should Be Equal` for an explanation of `msg`.
        The given dictionary is never altered by this keyword.
        """
        self.dictionary_should_contain_key(dictionary, key, msg)
        actual, expected = unicode(dictionary[key]), unicode(value)
        default = "Value of dictionary key '%s' does not match: %s != %s" % (key, actual, expected)
        _verify_condition(actual == expected, default, msg)
开发者ID:userzimmermann,项目名称:robotframework-python3,代码行数:12,代码来源:Collections.py

示例7: copy

    def copy(cls, url_obj):
        if not isinstance(url_obj, Url):
            raise TypeError('url_obj should be an Url object')

        u = Url(unicode(url_obj.entity_name))
        entity_id = url_obj.entity_id
        u.entity_id = unicode(entity_id) if entity_id is not None else None
        u.path = list(url_obj.path)
        u.prefix = unicode(url_obj.prefix)
        u._query = dict(url_obj._query)

        return u
开发者ID:kyukyukyu,项目名称:dash,代码行数:12,代码来源:test_api.py

示例8: test_run_revsort

 def test_run_revsort(self):
     outDir = self._createTempDir()
     self._tester('src/toil/test/cwl/revsort.cwl',
                  'src/toil/test/cwl/revsort-job.json',
                  outDir, {
         # Having unicode string literals isn't necessary for the assertion but makes for a
         # less noisy diff in case the assertion fails.
         u'output': {
             u'path': unicode(os.path.join(outDir, 'output.txt')),
             u'basename': unicode("output.txt"),
             u'size': 1111,
             u'class': u'File',
             u'checksum': u'sha1$b9214658cc453331b62c2282b772a5c063dbd284'}})
开发者ID:brainstorm,项目名称:toil,代码行数:13,代码来源:cwlTest.py

示例9: _populate_children

 def _populate_children(self, datadir, children, include_suites, warn_on_skipped):
     for child in children:
         try:
             datadir.add_child(child, include_suites)
         except DataError as err:
             self._log_failed_parsing("Parsing data source '%s' failed: %s"
                         % (child, unicode(err)), warn_on_skipped)
开发者ID:userzimmermann,项目名称:robotframework-python3,代码行数:7,代码来源:populators.py

示例10: add

def add(message, history_dir):
    _check_history_dir(history_dir)
    message = unicode(message)
    hashed = _make_hash_name(message)
    filepath = history_dir / hashed
    with filepath.open('w') as history_entry:
        history_entry.write(message + '\n')
开发者ID:beregond,项目名称:pyhistory,代码行数:7,代码来源:pyhistory.py

示例11: test_import_non_existing_module

 def test_import_non_existing_module(self):
     msg = ("Importing test library '%s' failed: ImportError: No module named "
            + ("'%s'" if PY3 else "%s"))
     for name in 'nonexisting', 'nonexi.sting':
         error = assert_raises(DataError, TestLibrary, name)
         assert_equals(unicode(error).splitlines()[0],
                       msg % (name, name.split('.')[0]))
开发者ID:userzimmermann,项目名称:robotframework-python3,代码行数:7,代码来源:test_testlibrary.py

示例12: _parse

 def _parse(self, path):
     try:
         return TestData(source=abspath(path),
                         include_suites=self.include_suites,
                         warn_on_skipped=self.warn_on_skipped)
     except DataError as err:
         raise DataError("Parsing '%s' failed: %s" % (path, unicode(err)))
开发者ID:userzimmermann,项目名称:robotframework-python3,代码行数:7,代码来源:builder.py

示例13: annotate_links

def annotate_links(answer_text):
    """
    Parse and annotate links from answer text and return the annotated answer
    and an enumerated list of links as footnotes.
    """

    try:
        SITE = Site.objects.get(is_default_site=True)
    except Site.DoesNotExist:
        raise RuntimeError('no default wagtail site configured')

    footnotes = []
    soup = bs(answer_text, 'lxml')
    links = soup.findAll('a')
    index = 1
    for link in links:
        if not link.get('href'):
            continue
        footnotes.append(
            (index, urljoin(SITE.root_url, link.get('href'))))
        parent = link.parent
        link_location = parent.index(link)
        super_tag = soup.new_tag('sup')
        super_tag.string = str(index)
        parent.insert(link_location + 1, super_tag)
        index += 1
    return (unicode(soup), footnotes)
开发者ID:contolini,项目名称:cfgov-refresh,代码行数:27,代码来源:views.py

示例14: start_keyword

 def start_keyword(self, kw):
     attrs = {'name': kw.name, 'type': kw.type}
     if kw.timeout:
         attrs['timeout'] = unicode(kw.timeout)
     self._writer.start('kw', attrs)
     self._writer.element('doc', kw.doc)
     self._write_list('arguments', 'arg', (unic(a) for a in kw.args))
开发者ID:userzimmermann,项目名称:robotframework-python3,代码行数:7,代码来源:xmllogger.py

示例15: _build_series

def _build_series(series, dim_names, comment, delta_name, delta_unit):
    from glue.ligolw import array as ligolw_array
    Attributes = ligolw.sax.xmlreader.AttributesImpl
    elem = ligolw.LIGO_LW(
            Attributes({u"Name": unicode(series.__class__.__name__)}))
    if comment is not None:
        elem.appendChild(ligolw.Comment()).pcdata = comment
    elem.appendChild(ligolw.Time.from_gps(series.epoch, u"epoch"))
    elem.appendChild(ligolw_param.Param.from_pyvalue(u"f0", series.f0,
                                                     unit=u"s^-1"))
    delta = getattr(series, delta_name)
    if numpy.iscomplexobj(series.data.data):
        data = numpy.row_stack((numpy.arange(len(series.data.data)) * delta,
                             series.data.data.real, series.data.data.imag))
    else:
        data = numpy.row_stack((numpy.arange(len(series.data.data)) * delta,
                                series.data.data))
    a = ligolw_array.Array.build(series.name, data, dim_names=dim_names)
    a.Unit = str(series.sampleUnits)
    dim0 = a.getElementsByTagName(ligolw.Dim.tagName)[0]
    dim0.Unit = delta_unit
    dim0.Start = series.f0
    dim0.Scale = delta
    elem.appendChild(a)
    return elem
开发者ID:tdent,项目名称:pycbc,代码行数:25,代码来源:live.py


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