线程并行调用,动作(Threading Parallel Invoke, Action)
我的代码如下
public void DownloadConcurrent(Action<string> Methord) { Action<string>[] methordList = new Action<string>[Concurent_Downloads]; for (int i = 0; i < Concurent_Downloads; i++) { methordList[i] = Methord; } Parallel.Invoke(methordList); }
Parallel.Invoke给出了错误:
"cannot convert from 'System.Action<string>[]' to 'System.Action[]'"
它正在调用的方法是
public void DownloadLinks(string Term) { }
My code as below
public void DownloadConcurrent(Action<string> Methord) { Action<string>[] methordList = new Action<string>[Concurent_Downloads]; for (int i = 0; i < Concurent_Downloads; i++) { methordList[i] = Methord; } Parallel.Invoke(methordList); }
Parallel.Invoke is giving error:
"cannot convert from 'System.Action<string>[]' to 'System.Action[]'"
The Method it is calling is
public void DownloadLinks(string Term) { }
原文:https://stackoverflow.com/questions/6533401
最满意答案
默认情况下,python 3.2可以使用unicode字符串,因此不再需要
u
。如果你想编码和解码字符串,你应该使用:
encoded = "unicodestring".encode("UTF8") decoded = s.decode("UTF8")
Python 3.0使用文本和(二进制)数据的概念,而不是Unicode字符串和8位字符串。 所有的文本都是Unicode的; 然而编码的Unicode表示为二进制数据。 用于保存文本的类型是str
和
Unicode文本不能再使用u“...”文字。 但是,对于二进制数据,您必须使用b“...”文字。
by default python 3.2 works with unicode strings so the
u
is no longer needed.If you want to encode and decode strings you should use:
encoded = "unicodestring".encode("UTF8") decoded = s.decode("UTF8")
The Python documetation states that:
Python 3.0 uses the concepts of text and (binary) data instead of Unicode strings and 8-bit strings. All text is Unicode; however encoded Unicode is represented as binary data. The type used to hold text is str
and
You can no longer use u"..." literals for Unicode text. However, you must use b"..." literals for binary data.
相关问答
更多-
IBM的ICU图书馆(和更多)。 它有Python绑定: PyICU 。 更新 :ICU和locale.strcoll之间排序的核心区别在于ICU使用完整的Unicode排序算法,而strcoll使用ISO 14651 。 这两个算法之间的差异在这里简要总结: http : //unicode.org/faq/collation.html#13 。 这些都是非常特殊的特例,在实践中很少涉及到。 >>> import icu # pip install PyICU >>> sorted(['a','b','c ...
-
正如其他人所说的那样,是两个不同的东西。 当你指定# -*- coding: utf-8 -*- ,你告诉Python你保存的源文件是utf-8 。 Python 2的默认值是ASCII(对于Python 3,它是utf-8 )。 这只会影响解释器如何读取文件中的字符。 一般来说,无论编码是什么,最好将非Unicode字符嵌入到文件中; 您可以使用字符串unicode转义,它可以在编码中工作。 当您在前面声明一个带有u的字符串时 ,就像u'This is a string' ,它告诉Python编译器该字符 ...
-
如何让Python 3正确处理MongoDB中的unicode字符串?(How to get Python 3 to correctly handle unicode strings from MongoDB?)[2022-04-15]
您无法存储Unicode。 这是一个概念。 MongoDB必须使用Unicode编码,它看起来像UTF-8 。 Python 3 Unicode字符串在内部存储为多种编码之一,具体取决于字符串的内容。 你有一个字符串解码为Unicode与错误的编码: >>> s='"C:\Some Folder\E=mc².xyz"' # The invalid decoding. >>> print(s) "C:\Some Folder\E=mc².xyz" >>> print(s.encode('latin1') ... -
默认情况下,python 3.2可以使用unicode字符串,因此不再需要u 。 如果你想编码和解码字符串,你应该使用: encoded = "unicodestring".encode("UTF8") decoded = s.decode("UTF8") Python documetation指出: Python 3.0使用文本和(二进制)数据的概念,而不是Unicode字符串和8位字符串。 所有的文本都是Unicode的; 然而编码的Unicode表示为二进制数据。 用于保存文本的类型是str 和 ...
-
您可以使用tokenize.generate_tokens将Python代码的字符串表示分解为令牌。 tokenize还会为您分类标记。 因此,您可以在Python代码中识别字符串文字。 然后操纵令牌并不困难,在需要'u'地方添加'u' import tokenize import token import io import collections class Token(collections.namedtuple('Token', 'num val start end line')): @p ...
-
请注意,在第一种情况下,打印结果的引用类似于“u'hello ....”这表示它正在打印Python字符串文字。 “r”前缀允许您在不转义字符串的情况下将反斜杠放入字符串中。 由于结果仅为“u”,因此必须转义每个反斜杠。 在第二种情况下,输出没有引用 - 因此它是字符串本身,而不是Python源代码中出现的字符串文字。 这显示了字符串的确切内容,而不是字符串,因为它必须编码为Python源代码。 Notice in the first case the printed result is quoted li ...
-
如何在python中逐字符地分割unicode字符串?(How to split unicode strings character by character in python?)[2022-02-13]
解决此问题的方法是将所有“L”类别字符与后续的“M”类别字符组合在一起: >>> regex.findall(ur'\p{L}\p{M}*', name) [u'\u0ba4', u'\u0bae\u0bbf', u'\u0bb4\u0bcd'] >>> for c in regex.findall(ur'\p{L}\p{M}*', name): ... print c ... த மி ழ் regex The way to solve this is to group all "L" categ ... -
Python:强制pprint将unicode字符串显示为字符串?(Python: Force pprint to display unicode strings as strings?)[2023-09-21]
您可以创建自己的PrettyPrinter对象并覆盖format方法。 import pprint def no_unicode(object, context, maxlevels, level): """ change unicode u'foo' to string 'foo' when pretty printing""" if pprint._type(object) is unicode: object = str(object) return ppri ... -
关于数据库方面,PostgreSQL本身不允许在char / text / varchar字段的字符串中使用空字节( '\0' ),因此如果您尝试存储包含它的字符串,则会收到错误。 例: postgres=# SELECT convert_from('foo\000bar'::bytea, 'unicode'); ERROR: 22021: invalid byte sequence for encoding "UTF8": 0x00 如果你真的需要存储这样的信息,那么你可以在PostgreSQL端使用 ...
-
您的代码按原样工作(除了您需要在Python 3中将print string1更改为print(string1) ;输出和返回值是字符串: country : . 但是,这在Python 2中不起作用,因为在Python 2中,字符串不是unicode ; 你需要在所有unicode字符串文字前加上u ,即u'浌' /或者你需要使用from __future__ import unicode_literals来''在Python 2中创建unicode文字; 并且chr还将值转换为8位字符串值(即字节),而 ...