defsharp_fix(url): """ the sharp (#) will incur some troubles in url param: url """ if url.find('#') >= 0: strs = url.split('#') if is_chinese(strs[1]): fix = urllib.parse.quote(strs[1]) fix = strs[0] + '%23' + fix return fix return url return url
判断字符串否包含中文
作用:对字符串是否包含有中文字符进行判断
1 2 3 4 5 6 7 8 9 10
defis_chinese(string): """ check whether the string includes the Chinese param: string """ for ch in string: ifu'\u4e00' <= ch <= u'\u9fff': returnTrue
if __name__ == "__main__": file_list = os.listdir() target = 'target.txt'
with open(target, 'a+', encoding='UTF-8') as source: #a+ w+ rb for file_name in file_list: if file_name.endswith('.txt') and file_name != target: with open(file_name, 'r', encoding='UTF-8') as file: print(file_name + 'done') for contents in file.readlines(): source.write(do_something(contents))