python - 将带有值的文本文件加载到 Python 中的元组中
问题描述
我有file.txt
这样的值的文本文件:
word1
word2
word3
word4
word5
我想要的是 Python 3 中这样的元组:
my_tuple = ('word1','word2','word3','word4','word5')
有什么建议吗?
解决方案
with open('file.txt','r') as f:
my_tuple=tuple(line.strip('\n') for line in f)
print(my_tuple)
# ('word1','word2','word3','word4','word5')
推荐阅读
- angular - Angular 反应式表单将表单组变成空表单控件
- react-native - React Native - 无效的钩子调用。钩子只能在函数组件的主体内部调用
- google-apps-script - 如果标题包含 x,则 Apps 脚本插入 2 列
- clojure - 允许任意规则顺序的语法
- angular - 无法通过选择读取材料表中未定义的属性“数据”
- c# - 根据注册表单中的一个文本框从数据库中获取值
- firebase - Xamarin.Firebase.Database 兼容性问题
- mongodb - 在 MongoDB 中对一组子文档进行排序(不使用聚合)
- c# - 如何将帖子值传递给 webapi .net 核心
- javascript - 访问 HTML 表格单元格并更改值