python - 如何读取 .array 文件并将数字传输到 Python 中的空列表中
问题描述
我正在尝试从名为sample.array
Python 的空列表中的文件中提取数字。
我已经尝试过通常的方式来读取文件,但结果却一无所获。
下面是我的代码和图片sample.array
:
import sys
import numpy as np
def read_file(filename):
"""
Your file will need to extract numbers from an array and
"""
list_of_numbers = []
file = open(sys.argv[1]).readline()
for number in file:
list_of_numbers.append(number)
print(list_of_numbers)
解决方案
暗示:
- 将文件作为单个字符串读取(谷歌它!)
- 然后拆分字符串。(谷歌这个呢!)。
推荐阅读
- javascript - Angular5 - 错误:使用无效数据调用函数 DocumentReference.set()。数据必须是一个对象,但它是:一个自定义的 PlatformModel 对象
- javascript - 当关注非“必需”文本框的文本框时,将占位符显示为标签
- javascript - 控制台不工作/状态不更新
- java - 依赖注入可以被认为是工厂方法模式的替代品吗?
- json - 构建基于 JSON 数组的 LINQ 查询
- quotes - 如何使用java排除检查引号中的单词
- angular - Firestore DocumentReference 类型检查不匹配
- python - 如何创建 Conda 包/应用程序的入口点?
- amazon-web-services - DynamoDB 本地数据库限制 - 用于初始 beta-go-live
- c - C代码中的字母顺序错误