首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >读取数据集并将其添加到双引号中

读取数据集并将其添加到双引号中
EN

Stack Overflow用户
提问于 2019-12-31 19:25:32
回答 1查看 25关注 0票数 0
代码语言:javascript
复制
Scott Logistics Corp
Transportation One LLC
Brothers Logistics Inc
Western Express Inc
Dart Advantage Logistics
Western Express Inc
Western Express Inc
Landstar Inway
Circle Logistics Inc

查看上面的数据集我想将每个名称添加到双引号中,例如("Scott物流公司“),或者看到下面我想要对此数据集做什么。

代码语言:javascript
复制
"Scott Logistics Corp"
"Transportation One LLC"
"Brothers Logistics Inc"
"Western Express Inc"
"Dart Advantage Logistics"
"Western Express Inc"
"Western Express Inc"
"Landstar Inway"
"Circle Logistics Inc"
....

我将从-1\f25 .txt -1文件中的-1\f25 dataset-1读取数据,并希望将其更改为-1\f25 dataset-1\f6,每个名称都用双引号括起来。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-31 19:58:57

如果你想添加双引号,那么纯python就足够了:

代码语言:javascript
复制
with open(r"text_1.txt",'r') as file:
    for line in file:
        line = re.sub(r'\n','',line)
        lines_new = (f'"{line}\"\n')
        with open("text_2.txt", "a") as f1:
            f1.writelines(lines_new)



"Scott Logistics Corp"
"Transportation One LLC"
"Brothers Logistics Inc"
"Western Express Inc"
"Dart Advantage Logistics"
"Western Express Inc"
"Western Express Inc"
"Landstar Inway"
"Circle Logistics Inc"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59543480

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档