gpt4 book ai didi

python - 在Python中读取#char

转载 作者:行者123 更新时间:2023-12-01 06:12:05 25 4
gpt4 key购买 nike

有人可以帮我在Python中读取“#”字符吗?我似乎无法获取该文件。因为这是 stanford postagger 的输出,是否有任何脚本可用于转换 stanford postagger http://nlp.stanford.edu/software/tagger.shtml文件到 cwb。 http://cogsci.uni-osnabrueck.de/~korpora/ws/CWBdoc/CWB_Encoding_Tutorial/node3.html

这是我要读取的 utf-8 txt 文件:

 如果#CS 您#PN 在#P 新加坡#NR 只#AD 能#VV 前往#VV 一#CD 间#M 俱乐部#NN ,#PU 祖卡#NN 酒吧#NN 必然#AD 是#VC 您#PN 的#DEG 不二#JJ 选择#NN 。#PU
作为#P 或许#AD 是#VC 新加坡#NR 唯一#JJ 一#CD 家#M 国际#NN 知名#VA 的#DEC 夜店#NN ,#PU 祖卡#NN 既#CC 是#VC 一#CD 个#M 公共#JJ 机构#NN ,#PU

因此,使用此代码,我不会读取 utf-8 txt 文件中的 # 字符:

#!/usr/bin/python # -*- coding: utf-8 -*-

'''
stanford POS tagger to CWB format
'''

import codecs
import nltk
import os, sys, re, glob

reload(sys)
sys.setdefaultencoding('utf-8')

cwd = './path/to/file.txt' #os.getcwd()

for infile in glob.glob(os.path.join(cwd, 'zouk.txt')):
print infile
(PATH, FILENAME) = os.path.split(infile)
reader = codecs.open(infile, 'r', 'utf-8')
for line in reader:
for word in line:
if word == '\#':
print 'hex is here'

最佳答案

if word == '\#':

这可能不会做你想象的那样。 (提示:打印“\#”)

关于python - 在Python中读取#char,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5280421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com