使用RMySQL进行UTF8编码(UTF8 encoding using RMySQL)
我正在尝试从包含一些字符串的mysql数据库中查询数据。 对于连接和数据检索,我在R中使用RMySQL,它工作正常。 除了一件事:我正在检索的字符串似乎不在utf8中。 但我需要这个,因为我在这些字符串中有一些德语“Umlaute”。 当我问数据库时,它是由它编码的
dbGetQuery(db, "SHOW VARIABLES LIKE 'character_set_%';")
我得到了理想的答案:
Variable_name Value 1 character_set_client utf8 2 character_set_connection utf8 3 character_set_database utf8 4 character_set_filesystem binary 5 character_set_results utf8 6 character_set_server utf8 7 character_set_system utf8 8 character_sets_dir C:\\Program Files\\MySQL\\MySQL Server 5.7\\share\\charsets\\
但是,例如我收到了
Andreas Wünsche
代替
Andreas Wünsche
希望有人知道如何处理它。 如果需要额外的信息,请问。 我可以提供。
I am trying to query data from a mysql database, which contains some strings, of course. For the connection and data retrieval I am using RMySQL in R, which works fine. Apart from one thing: the strings I am retrieving seem not to be in utf8. But I need this, because I have some german "Umlaute" in these strings. When I ask teh databse, which are its encoding by
dbGetQuery(db, "SHOW VARIABLES LIKE 'character_set_%';")
I get the desired answer:
Variable_name Value 1 character_set_client utf8 2 character_set_connection utf8 3 character_set_database utf8 4 character_set_filesystem binary 5 character_set_results utf8 6 character_set_server utf8 7 character_set_system utf8 8 character_sets_dir C:\\Program Files\\MySQL\\MySQL Server 5.7\\share\\charsets\\
But e.g. I receive
Andreas Wünsche
instead of
Andreas Wünsche
Hope that somebody knows how to deal with it. If additonal information is needed, just ask. I can provide it.
原文:https://stackoverflow.com/questions/38347348
最满意答案
如果我正确理解你,你需要做的是:
dictionary["owner"] = dictionary["owner"]["name"]
这会将密钥“所有者”的值更改为密钥“名称”的值。
If I understand you correctly, all what you need to do is:
dictionary["owner"] = dictionary["owner"]["name"]
This will change the value of the key "owner", to the value of the key "name".
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
根据属于字典中特定键的值创建数组(Swift 4)(Make an array from values belonging to a specific key in a dictionary (Swift 4))[2023-09-09]
randomQuote中有很多小东西需要修复。 不需要第二次使用Array(...) 。 database[someKey]已经为您提供了引号数组。 你还有一些你不需要的额外括号。 这是包含所有修复的更新代码: func randomQuote(){ //Make an array from database keys var authorArray = Array(database.keys) //Pick a random author let author = aut ... -
您可以使用if子句检查它们是否存在于内部字典中 >>> for k,v in dictofdict.items(): ... if 'date' in v and 'status' in v: ... print("{}\t{}\t{}".format(v['date'],k,v['status'])) ... 201504 003 In Review 201504 002 Constant 201504 001 New 如果您特别关注订单,那么您将不得不使用sort ...
-
如果我正确理解你,你需要做的是: dictionary["owner"] = dictionary["owner"]["name"] 这会将密钥“所有者”的值更改为密钥“名称”的值。 If I understand you correctly, all what you need to do is: dictionary["owner"] = dictionary["owner"]["name"] This will change the value of the key "owner", to the ...
-
要回答第二个问题,关于如何改进您正在使用的循环,它可以得到显着改善。 目前,如果列表视图中有100个项目,目录中有10个项目,则代码将循环至少1000次,并且最多可循环10次,具体取决于目录中使用的值以及是否显示ShowDescriptions被标记。 通过在进入赋值循环之前使用适当的键构建字典,我们可以将直接循环减少到110次: If ListView_Monitor.Items.Count <> 0 Then Dim DirectoriesByCurrentKey As New ...
-
你不能开箱即用,但你可以使用自定义模板标签。 请查看这个旧的Django票证以获得可能的解决方案,并且理由被拒绝: 通过变量值作为键访问dict值 You cannot do that out of the box, but you can do with a custom template tag. Please see this old Django ticket for a possible solution, and for the reason the idea got rejected:Acce ...
-
将你的字典换成列表并移出代码。 代替 data = {'code':'this is the code', 'some':'other', 'stuff':'here'} 做 data = ['this is the code', {'some':'other', 'stuff':'here'}] Wrap your dict in a list and move your code out. Instead of data = {'code':'this is the code', 'some':'o ...
-
非泛型的IDictionary不使用KeyValue
类型,所以你永远不会有任何匹配。 您需要解析DictionaryEntry项目并将其转换: Dictionary dict = myIDictionary .Cast () .Where(de => de.Key is K && de.Value is V) ... -
计算python字典的特定键中的值的数量(counting the number of values in a specific key for a python dictionary)[2023-09-11]
发生这种情况是因为当你只用一个值保存像cc这样的值时,它只是保存为一个int而不再是一个元组,这意味着它没有len()函数。 您只需添加值的type检查,例如: if type(d[key]) == int: print(1) else: print(len(d[key])) 这样,您将不会尝试访问int的length属性,也不会得到您的错误。 This is happening because when you save a value like cc with only one val ... -
你有一个带有键的字典:值对,其中值是一个列表。 要引用此列表中的值,请执行常规字典引用,即 dict['chmi'] 但是你需要添加一种操作列表的方法。 您可以使用任何列表方法,或只使用列表切片,即 dict['chmi'][0] 将返回key chmi引用的列表的第一个元素。 您可以使用 dict['chmi'][dict['chmi'].index('48680')] 引用48680元素。 我在这里做的是打电话给 list.index(ele) 方法,返回元素的索引,然后我通过使用切片引用 ...