ACCC1380 commited on
Commit
03f10c1
1 Parent(s): db225fe

Upload 1_xingye/Untitled.ipynb with huggingface_hub

Browse files
Files changed (1) hide show
  1. 1_xingye/Untitled.ipynb +64 -0
1_xingye/Untitled.ipynb ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 2,
6
+ "id": "652d02d5-2c81-4607-a8df-8e14876bef28",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stdout",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "处理完成!\n"
14
+ ]
15
+ }
16
+ ],
17
+ "source": [
18
+ "import os\n",
19
+ "import re\n",
20
+ "\n",
21
+ "# 指定目录路径\n",
22
+ "directory = './'\n",
23
+ "\n",
24
+ "# 遍历目录下所有的txt文件\n",
25
+ "for filename in os.listdir(directory):\n",
26
+ " if filename.endswith('.txt'):\n",
27
+ " file_path = os.path.join(directory, filename)\n",
28
+ " \n",
29
+ " with open(file_path, 'r', encoding='utf-8') as file:\n",
30
+ " content = file.read()\n",
31
+ " \n",
32
+ " # 移除大括号、引号和单引号\n",
33
+ " content = re.sub(r'[{}\\'\"]', '', content) # 移除大括号、单引号和引号\n",
34
+ " content = re.sub(r\"<MORE_DETAILED_CAPTION>':\", '', content) # 移除特定字符串\n",
35
+ "\n",
36
+ " with open(file_path, 'w', encoding='utf-8') as file:\n",
37
+ " file.write(content)\n",
38
+ "\n",
39
+ "print(\"处理完成!\")\n"
40
+ ]
41
+ }
42
+ ],
43
+ "metadata": {
44
+ "kernelspec": {
45
+ "display_name": "Python 3",
46
+ "language": "python",
47
+ "name": "python3"
48
+ },
49
+ "language_info": {
50
+ "codemirror_mode": {
51
+ "name": "ipython",
52
+ "version": 3
53
+ },
54
+ "file_extension": ".py",
55
+ "mimetype": "text/x-python",
56
+ "name": "python",
57
+ "nbconvert_exporter": "python",
58
+ "pygments_lexer": "ipython3",
59
+ "version": "3.10.10"
60
+ }
61
+ },
62
+ "nbformat": 4,
63
+ "nbformat_minor": 5
64
+ }