en_file_path = 'C:\Users\yyyyyds\Desktop\wyt\23级作业2\corpus' 怎么修改
时间: 2024-04-21 08:21:37 浏览: 95
根据提供的引用内容,你遇到了一个文件路径错误的问题。你可以按照以下方法进行修改:
1. 使用原始字符串(raw string)来表示文件路径,以避免转义字符的干扰[^1]。
```python
en_file_path = r'C:\Users\yyyyyds\Desktop\wyt\23级作业2\corpus'
```
2. 将文件路径中的反斜杠`\`替换为正斜杠`/`。
```python
en_file_path = 'C:/Users/yyyyyds/Desktop/wyt/23级作业2/corpus'
```
3. 使用双反斜杠`\\`来表示反斜杠`\`,因为反斜杠在字符串中有特殊含义。
```python
en_file_path = 'C:\\Users\\yyyyyds\\Desktop\\wyt\\23级作业2\\corpus'
```
4. 使用`os.path`模块来处理文件路径,它可以根据操作系统自动选择正确的路径分隔符。
```python
import os
en_file_path = os.path.join('C:', 'Users', 'yyyyyds', 'Desktop', 'wyt', '23级作业2', 'corpus')
```
请注意,以上方法中的每一种都可以解决你遇到的文件路径错误问题。你可以根据自己的需求选择其中一种方法进行修改。
相关问题
"" base64编解码处理 用于处理某些被加密的敏感词库 author : @h-j-13 time : 2018-7-18 """ import os import base64 def decode64file(path_file): """解码base64加密的文件""" with open(path_file, 'rb') as f: str_set = set() for line in f: s = line.strip() # strip()方法消除多余的空格之类的特殊字符 if s.endswith(b'Cg=='): s = s.replace(b'Cg==', b'') str_set.add(base64.b64decode(s)) return str_set train_data_url = r"C:\Users\曹福滨\Downloads\tc-corpus-\answer" def get_all_file_by_path(path=train_data_url): """获取某个目录下的所有训练文件""" file_path = [] dir_list = os.listdir(train_data_url) for d in dir_list: file_path.extend(map(lambda x: train_data_url + d + '/' + x, os.listdir(train_data_url + d))) return file_path def decode_file2utf8(file_path): """将文件从GB2312编码解码为utf8文件""" decode_error = False file_data = [] with open(file_path, 'r') as f: for l in f.readlines(): try: tmp = l.encode('gbk').decode('utf8') except Exception as e: decode_error = True tmp = '' file_data.append(tmp) if decode_error: os.remove(file_path) else: with open(file_path, 'w') as f: f.writelines(file_data) if __name__ == '__main__': for p in get_all_file_by_path(): decode_file2utf8(p)
这段代码是用来解码base64加密的文件,主要是用于处理一些被加密的敏感词库。作者是@h-j-13,时间是2018年7月18日。代码中使用了Python的os和base64模块,其中decode64file函数接受一个文件路径作为参数,读取文件内容并解码,最终返回一个字符串集合。
if __name__ == "__main__": device = "cuda:0" if torch.cuda.is_available() else "cpu" with open("datas\\chinese_vec.pkl","rb") as f1: #rb显示为二进制 _, ch_word_2_index,ch_index_2_word = pickle.load(f1) with open("datas\\english_vec.pkl","rb") as f2: _, en_word_2_index, en_index_2_word = pickle.load(f2) ch_corpus_len = len(ch_word_2_index) en_corpus_len = len(en_word_2_index) ch_word_2_index.update({"<PAD>":ch_corpus_len,"<BOS>":ch_corpus_len + 1 , "<EOS>":ch_corpus_len+2}) en_word_2_index.update({"<PAD>":en_corpus_len}) ch_index_2_word += ["<PAD>","<BOS>","<EOS>"] en_index_2_word += ["<PAD>"] 解释每行代码的含义
如果如果__如果__name如果__name__如果__name__ ==如果__name__ == "__如果__name__ == "__main如果__name__ == "__main__如果__name__ == "__main__":如果__name__ == "__main__":
如果__name__ == "__main__":
则如果__name__ == "__main__":
则执行如果__name__ == "__main__":
则执行下如果__name__ == "__main__":
则执行下列如果__name__ == "__main__":
则执行下列代码如果__name__ == "__main__":
则执行下列代码:
如果__name__ == "__main__":
则执行下列代码:
如果如果__name__ == "__main__":
则执行下列代码:
如果torch如果__name__ == "__main__":
则执行下列代码:
如果torch可如果__name__ == "__main__":
则执行下列代码:
如果torch可用如果__name__ == "__main__":
则执行下列代码:
如果torch可用的如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0"如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu"如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\ch如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件,如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件,以如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件,以二如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件,以二进如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件,以二进制如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件,以二进制读如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件,以二进制读取如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件,以二进制读取模如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件,以二进制读取模式如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件,以二进制读取模式,如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件,以二进制读取模式,赋如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件,以二进制读取模式,赋值如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件,以二进制读取模式,赋值给如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件,以二进制读取模式,赋值给f如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件,以二进制读取模式,赋值给f1如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件,以二进制读取模式,赋值给f1变如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件,以二进制读取模式,赋值给f1变量如果__name__ == "__main__":
则执行下列代码:
如果torch可用的话,将device设置为"cuda:0",否则设为"cpu";
打开名为"datas\\chinese_vec.pkl"的文件,以二进制读取模式,赋值给f1变量。
阅读全文
相关推荐

















