思路:在SQL中创建一个函数fn_GetPy(),函数的输入参数是一个汉字字符串,返回值是拼音码字符串. 创建函数语句: CREATE function fn_GetPy(@str nvarchar(4000)) returns nvarchar(4000) --WITH ENCRYPTION as begin declare @intLen int declare @strRet nvarchar(4000) declare @temp nvarchar(100) set @intLen =
def SplitHtmlTag(file): with open(file,"r") as f,open("result.txt","w+") as c: lines=f.readlines() for line in lines: re_html=re.compile(r'<[^>]+>')#从'<'开始匹配,不是'>'的字符都跳过,直到'>' line=re_html.sub('',line) c.wri
pandas 操作csv文件时,一直报错,排查后发现csv文本中存在很多“空行”: So 需要把空行全部去掉: def clearBlankLine(): file1 = open('text1.txt', 'r', encoding='utf-8') # 要去掉空行的文件 file2 = open('text2.txt', 'w', encoding='utf-8') # 生成没有空行的文件 try: for line in file1.readlines(): if line == '\n'
需求 read some .txt file in dir and find min and max num in file. solution: echo *.txt > file.name in linux shell >>>execfile("mytest.py"); //equivalent to run mytest.m in matlab import os fileobj = open("./test2images/2d_xxx.name
1.读文件,通过正则匹配 def statisticWord(): line_number = 0 words_dict = {} with open (r'D:\test\test.txt',encoding='utf-8') as a_file: for line in a_file: words = re.findall(r'&#\d+;|&#\d+;|&\w+;',line) for word in words: words_dict[word] = words_dict.
import re import os input_path = 'G:/test/aa.json' output_path ='G:/test/bb.json' with open(input_path) as input_file: str = input_file.read() str = re.sub('\s','',str) print str with open(output_path, 'w') as output_file: output_file.write(str)
1.hanlp简介 HanLP是一系列模型与算法组成的NLP工具包,由大快搜索主导并完全开源,目标是普及自然语言处理在生产环境中的应用.HanLP具备功能完善.性能高效.架构清晰.语料时新.可自定义的特点. 开源网址:HanLP: Han Language Processing 但由于hanlp是用java来实现的,要在python中使用hanlp,只能通过调用pyhanlp这个包来. 但是pyhanlp里面有一些功能仍然不支持python直接调用,比如汉字转拼音,这时候就需要从python中启