Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Python utf-8字符串馈送到Scala_Python_Scala_Unicode - Fatal编程技术网

将Python utf-8字符串馈送到Scala

将Python utf-8字符串馈送到Scala,python,scala,unicode,Python,Scala,Unicode,我使用subprocess将Python中生成的字符串传递给Scala程序 (此处为软件包的cli) 有问题的字符串之一是 "thomasholgerhst\xfctzlehoos" 有没有一种方法可以在Python中设置unicode字符串的格式,使其易于被Scala接受 另外,我还没有用Scala编写程序。要在python中声明unicode字符串,请在字符串文本前面加上u。因此,不要使用“thomasholgerhst\xfctzlehoos”而使用u“mystringliteral”

我使用subprocess将Python中生成的字符串传递给Scala程序

(此处为软件包的cli)

有问题的字符串之一是

"thomasholgerhst\xfctzlehoos" 
有没有一种方法可以在Python中设置unicode字符串的格式,使其易于被Scala接受


另外,我还没有用Scala编写程序。

要在python中声明unicode字符串,请在字符串文本前面加上u。因此,不要使用
“thomasholgerhst\xfctzlehoos”
而使用
u“mystringliteral”
。然后,要将unicode字符串转换为utf-8,请使用
.encode(“utf-8”)


你是怎么读的?如果您是从磁盘上的文件获取字符串,则在Scala读取该字符串时,您应该能够指定该字符串的编码。@KChaloux字符串首先加载到Python字典中,然后通过子进程发送到Scala cli。我使用unicode(str_1,“utf-8”)将字符串输入Scala程序之前。或者,您可以在代码开头使用
#-*-编码:utf-8-*-
将所有字符串文本标记为utf-8编码。
u"mystringliteral".encode("utf-8")