两个unicode字符串的串联? [英] concatenation of two unicode srings?
问题描述
#!/ usr / bin / python
#-*-编码:utf-8-*-
import re
分隔符= [u。,u,,u。]
dat = open(r C:\Users\User\Desktop\text4.txt,'r') .read()
text = dat.decode( utf-8)
wros = text.split()
out =
导入字符串
空格=
counter = 0;
中的单词:
out = u .join(word)
writ = open( C:\\Users\\User\ \Desktop\\text5.txt,'w')
writ.write(out.encode('utf-8'))
writ.close()
text4.txt包含
text5.txt输出为ह。
所需的输出是 请告诉我我在做什么错了?需要帮助!预先感谢 我不知道您与 text4.txt contains text5.txt outputs as desired output is please tell me what i am doing is wrong ? HElp required ! thanks in advance I don't know what you have to do with
这篇关于两个unicode字符串的串联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
word $ c有什么关系$ c>,但我会这样:
text = open('text4.txt')。read()
text = text.decode( utf-8)
#将一个字符串分成(旧)单词列表
单词= text.split()
#新单词列表
out = []
#修改单词
替换单词:
#此处-使用`word`
out.append(word)
#将所有新单词连接到一个字符串
result = u''.join(out)
result = result.encode('utf-8')
writ = open('text5.txt','w')
writ.write(result)
writ .close()
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
separators = [u"।", u",", u"."]
dat=open(r"C:\Users\User\Desktop\text4.txt",'r').read()
text=dat.decode("utf-8")
wros=text.split()
out=""
import string
space=" "
counter=0;
for word in wros:
out=u" ".join(word)
writ=open("C:\\Users\\User\\Desktop\\text5.txt",'w')
writ.write(out.encode('utf-8'))
writ.close()
भारत का इतिहास काफी समृद्ध एवं विस्तृत है।
ह ै ।
भारत का इतिहास काफी समृद्ध एवं विस्तृत है।
word
but I would do it this way:text = open('text4.txt').read()
text = text.decode("utf-8")
# split one string into list of (old) words
words = text.split()
# list for new words
out = []
# modify words
for word in words:
# here - do something with `word`
out.append(word)
# concatenate all new words to one string
result = u' '.join(out)
result = result.encode('utf-8')
writ = open('text5.txt', 'w')
writ.write(result)
writ.close()