首页 \ 问答 \ 线程并行调用,动作(Threading Parallel Invoke, Action)

线程并行调用,动作(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
更新时间:2021-04-10 12:04

最满意答案

默认情况下,python 3.2可以使用unicode字符串,因此不再需要u

如果你想编码和解码字符串,你应该使用:

encoded = "unicodestring".encode("UTF8")

decoded = s.decode("UTF8")

Python documetation指出:

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编译器该字符 ...
  • 您无法存储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 ...
  • 解决此问题的方法是将所有“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 ...
  • 您可以创建自己的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位字符串值(即字节),而 ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)